Split out from #2168241: Type hints for optional methods in StatementInterface (D8) / DatabaseStatementInterface (D7), this contains many docblock improvements, that I hope are fairly straightforward to review.
It does not introduce any {@inheritdoc}, because reviewing these would require to verify that the interface method or overridden method actually exists. So, {@inheritdoc} goes into a separate issue.
It is also very possible that some or even many methods in the database system are not covered by this patch.
Imo, we should get this in nevertheless, the patch is big enough.
To do:
Create Child issues for remaining items:
core/lib/Drupal/Core/Database/Connection.php
core/lib/Drupal/Core/Database/Database.php
core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
core/lib/Drupal/Core/Database/Driver/mysql/Schema.php
core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php
core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php
core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php
- core/lib/Drupal/Core/Database/Install/Tasks.php
core/lib/Drupal/Core/Database/Log.php
core/lib/Drupal/Core/Database/Query/AlterableInterface.php
core/lib/Drupal/Core/Database/Query/Condition.php
core/lib/Drupal/Core/Database/Query/ConditionInterface.php
core/lib/Drupal/Core/Database/Query/Delete.php
core/lib/Drupal/Core/Database/Query/Insert.php
core/lib/Drupal/Core/Database/Query/PagerSelectExtender.php
core/lib/Drupal/Core/Database/Query/PlaceholderInterface.php
core/lib/Drupal/Core/Database/Query/Query.php
core/lib/Drupal/Core/Database/Query/Select.php
core/lib/Drupal/Core/Database/Query/SelectExtender.php
core/lib/Drupal/Core/Database/Query/SelectInterface.php
core/lib/Drupal/Core/Database/Query/TableSortExtender.php
core/lib/Drupal/Core/Database/Query/Truncate.php
core/lib/Drupal/Core/Database/Query/Update.php
core/lib/Drupal/Core/Database/Schema.php
core/lib/Drupal/Core/Database/Statement.php
core/lib/Drupal/Core/Database/StatementInterface.php
core/lib/Drupal/Core/Database/StatementPrefetch.php
Comments
Comment #1
donquixote commentedComment #2
Crell commented"The generated SQL string" or "A generated SQL string". An article is needed at the start of the sentence.
Shouldn't these have descriptions like everything else?
Shouldn't this be {@inheritdoc}?
Needs short descriptions.
Article needed, as above.
Descriptions needed.
A number of others are still needed, but I'm going to stop mentioning it to save myself time. :-)
Oh for PHP 5.6... :-)
Should be namespaced.
(Although IDEs are increasingly recognizing classes in docblocks relative to the namespace of the file, which is great. We may want to revisit that standard at some point...)
"an of two strings". A what? An array of two strings?
"mixed" already implies array and object. This method is silly. :-)
Comment #3
bburgLooking at this issue during the Forum One code sprint.
On 2, Would it be more appropriate to provide detailed descriptions in Drupal\Core\Database Connection rather than providing the same descriptions in all the driver specific classes?
Comment #4
Crell commentedThe parent class should have the descriptions. (Not long ones, just the few words needed.) The child classes can probably then use {@inheritdoc} and be done with it.
Comment #5
bburgAttached are is the updated patch with Crell's suggestions, plus a few other spelling/grammar corrections I came across. Donquixote is right, there are a large number of methods in the driver specific classes that require {@inheritdoc} annotations.
Comment #6
xanoSee #2192185: Improve DB API code documentation as well.
Comment #7
Crell commentedWhy remove the type specification here?
Otherwise I think this is "close enough" to commit. I just had to postpone #2192185: Improve DB API code documentation again on this issue; there's too many DB-doc-cleanup issues floating around. Let's get at least some of them committed.
Comment #8
donquixote commentedAnd a missing type here.
(Btw, sorry for letting this rot for so long, and thanks for picking it up!)
Comment #9
donquixote commentedOther than that, I agree with the "close enough" approach.
Any partial improvement is better than letting this sit around - so long as it does not contain any regressions.
I did not study the @inheritdoc in the recent patch in detail. I just want to say we need to be careful if a method has two parents - e.g. one interface method and one parent class method. In this case, it might be preferable to use explicit docblock instead of @inheritdoc, and link to the parents with a @see tag.
I am also not sure about @inheritdoc in constructors - maybe others have an opinion about that?
I would personally prefer "The name of the table", if this is what it is (as opposed to a table alias, or a table object).
Comment #10
donquixote commented@Crell (#2)
The idea here was that even without descriptions this would be an improvement, and one that we can pull off with little effort.
Whereas adding poor descriptions out of ignorance would be worse than leaving this to a follow-up.
Of course now that @bburg has jumped in, I am happy to see the descriptions being added.
Comment #11
jhodgdonAdding @param tags that lack descriptions is not much of an improvement over not having them at all. Anyone can look at the function signature and see what the parameters are, anyway, so all you're getting is the (possibly accurate) data type of the parameter being added. Many function signatures have that in type hinting already.
Comment #12
Crell commentedjhodgdon: If we addressed #7 would you be OK committing this? This is like the 4th "futz with database docblocks" issue and I want to get at least one of them committed, just to make forward progress at all. :-(
Comment #13
jhodgdonI haven't looked at the patch. What exactly are you asking me to overlook?
I'd be happy to commit a patch that fixes some files, and conforms to our standards (like having descriptions for @return/@param, except in the case of @return $this, which by our standards doesn't require a description). I'm less happy to commit patches that don't bring the docs into closer confirmation to our standards.
The other problem with these huge patches is that as a committer, I am obligated to give them a final review before I commit them, or at least I feel that obligation. If the patch is 1000 lines, I need to at least glance through all 1000 lines, and there is a near 100% certainty that I'll find something that isn't right. I really don't want to commit patches that introduce errors, like incorrect types or misleading documentation (I'd rather have no documentation than wrong documentation -- at least if there is no docs it says "sorry, no docs, guess you'll have to read the code!)
Given that, I'd much rather have 10 smaller patches of 100 lines than one of 1000 lines -- at least if 9 of the 10 were perfect I could go ahead and commit them, rather than stalling the entire 1000 lines of patching. These huge patches are just really really hard to get right and really difficult to deal with.
Comment #14
yesct commentedComment #15
pcorbett commentedRe-rolled with as many type specifications as I could find missing with @Crell 's help. First big re-roll for me! (fingers crossed)
Comment #16
pcorbett commentedN00b alert :) Attaching actual patch as well.
Comment #17
Crell commentedThis patch could do more; there's definitely some docblocks in it that could use work.
However, it's nearly 100KB and from my read through just now I don't see any chunk that makes anything worse; they all make the situation better, just maybe not as better as it could get. That's for follow-up patches if we ever hope of getting anything in. :-)
Thus, RTBC. jhodgdon, over to you.
Comment #18
alexpottTo keep this in scope I've only reviewed the proposed changes.
Should be
@return \Drupal\Core\Database\StatementInterface|int|nullLets add docs here
No line saying what the method does
Needs a new line and the method name seems to suggest a missing @return
Should have a line saying what is returned.
@throws should have a line saying why this occurs.
param doc missing
Missing description of return value
Missing new line between @throws and @return and also need a line describing why exception is thrown
Missing method description one liner and param descriptions.
Missing @return description
Missing param description
Missing @return description
Missing method description and parameter descriptions.
Should be a fully namespaced reference to PlaceHolderInterface
Should be a fully namespace reference to SelectInterface
Should be a fully namespaced reference to SelectInterface
Needs method one liner and param description
Needs method one liner and param description
Missing @return description
Needs method one liner and param description
Needs method one liner and param description
Comment #19
Crell commentedAlex: As I said, this patch could be better but doesn't make anything *worse*. It's also 100 KB, and is at least the third attempt to update documentation in the DB layer that we've had; they keep stalling on "who wants to deal with big patches that somehow seem to break often". As DB maintainer I don't care if the patch is perfect. I care that it's forward progress. Caring about perfect is why none of these have been committed in the last year.
Unless anything in this patch is actually *wrong*, please let it through. There will be follow-ups, many of them, but "the best is the enemy of the good" at this point.
Comment #20
jhodgdonCrell: I agree with Alex. I don't think that changes like his example #21 and #22 are improvements. I don't agree with the philosophy of adding a bunch of doc blocks to the code base that are way out of compliance with our documentation standards. Having no doc block, in my opinion, is preferable to one that just gives the data type of parameters. Doc blocks get copied around... these ones are not good.
Please just try for a smaller patch of actually good documentation, rather than a huge patch that doesn't improve much.
Comment #21
donquixote commented> Should be @return \Drupal\Core\Database\StatementInterface|int|null
I personally don't care so much about descriptions (my IDE wants type docs).
But this is something we should fix. If we add type docs, they should be correct.
Comment #22
jhodgdonYeah, I definitely do not want to commit docs that give incorrect information -- would rather have no docs than incorrect docs -- at least if no docs, you know you have to read the code.
Comment #23
donquixote commented(Sorry, I had no time for this until now.)
I feel tempted to fix even more method docblocks than in #16, but I refrain from that to not further blow up the patch.
@jhodgdon:
A nice read about the value of static typing (and thus, type hints in a weakly typed language) http://techblog.realestate.com.au/the-abject-failure-of-weak-typing/ (thanks @Crell for the tweet)
@alexpott (#18):
1.
Fixed.
But I also had to update the description, because it did a rather poor job of documenting the NULL case.
@Crell: I prefer dedicated methods over these overly flexible signatures, but yeah.. whatever.
2.
(for ..\mysql\Schema::getPrefixInfo())
As I see it, the types in this case are trivial, but the descriptions are not. E.g. $table could be "$dbname.$tablename" or just "$tablename", and we would need to explain why the prefix is to be added either to the dbname or the tablename.
I would rather see the description fixed in a follow-up, instead of adding a wrong description, or further slowing down this issue.
However, the type of $table is always going to be string, so this is quite safe to add. And $add_prefix is clearly a boolean.
My IDE will be happy to have this documented.
5. (..\sqlite\Connection\sqlFunctionSubstring())
Noticed that this can also return FALSE, if substr() returns false.
@Crell: Is this return value appropriate for the database / sqlite? I added a @todo there..
6. (..\sqlite\Connection::prepare())
I think there is absolutely no reason why this would occur. The @throws should be removed.
Drupal\Core\Database\Driver\sqlite\Connection::prepare() constructs a Drupal\Core\Database\Driver\sqlite\Statement, which inherits the constructor from Drupal\Core\Database\StatementPrefetch::__construct(), which really does not do anything "exceptional".
@Crell, do you agree?
11.
Not really sure what PagerSelectExtender does, so I leave this to others.
12.
Again, would prefer someone else to do this.
13.
Adding a rather redundant "The unique identifier" @return doc. This is the most I feel qualified to do.
19.
This added doc seems to be wrong. We want a \Drupal\Core\Database\Connection, not a \Drupal\Core\Database\Driver\Sqlite\Connection. Either way, adding a (rather redundant) comment saying "The database connection".
20.
Adding a rather redundant "The unique identifier.". I would really be interested where this unique identifier comes from and what it identifies, but this should be filled in by someone else.
The Schema::$uniqueIdentifier doc is also not very satisfactory. "A unique identifier for this query object.". What query? Isn't this just a schema?
22. (StatementPrefetch::__construct())
@Crell: I'm a little confused because Statement::__construct() has just one "Connection $dbh" argument, whereas StatementPrefetch has two connection arguments: "\PDO $dbh, Connection $connection".
Comment #24
donquixote commentedComment #25
donquixote commentedCreated the issue #2337035: [policy] Allow patches that only add doc types, but no descriptions, for incremental improvement, so I don't have to side-track this one.
Comment #26
bburgI kept thinking of this issue while painting my deck today... It seems that a few items are what's holding up this patch, but also no one seems particularly thrilled with the current state of it either. I'd like to second jhodgdon's suggestion in #13 of breaking this up into several, smaller issues. Some further rational:
By my count, this patch currently touches 28 different files (listed below), so why not a new issue for each? I volunteer to create these issues, post starter patches from the work above in each one and update this issue to track those.
Comment #27
Crell commentedI am at the point of giving up on any chunk larger than an individual method as far as cleaning up the DB documentation goes. We've been trying for a long time now and it never takes and always runs into roadblocks. If you want to try splitting it up that fine-grained to see if we can novice-ify them you have my blessing but this is not a priority for me at this point.
Comment #28
donquixote commented@bburg
Could we maybe start with just one of those, to prove to ourselves that the possibility to commit something is not just hypothetical, and that smaller (but more) issues really improve the situation?
@Crell
Aside of whether this is being split up or discussed as one, #23 had some questions that are best answered by an expert of the database system, (if we can get our hands on the author that would be ideal)
Sure, I could also re-ask this stuff in the respective sub-issue..
Comment #29
bburgStarting out with #2342521: Docblock fixes for core/lib/Drupal/Core/Database/Connection.php
Comment #30
bburgComment #31
jhodgdonThanks!
28 child issues is also a lot... Maybe there is a happy medium between "one issue per file" and "one big issue" that would make the patches more manageable but not create tons of issues either? The one you did is fine, but maybe patches of about that size or 2-3 times as big would still be OK. So if you find files that don't have tons of changes, you could do a few together in one issue?
Comment #32
donquixote commentedMaybe one issue per subfolder?
Comment #33
jhodgdonThat would be a good solution, yes (#32)... some subfolders could also be broken up like maybe "Query subfolder, files A-M" if the patches get too large (I just made that example up).
Comment #34
bburgOther files directly in the core/lib/Drupal/Core/Database/ subdir covered in #2343099: Add @param and @return or fix types in @param and @return in core/lib/Drupal/Core/Database/ (Connection.php on its own was 100 lines, so let's just keep that in its own for now).
Comment #35
bburg#2343121: Docblock fixes for core/lib/Drupal/Core/Database/Driver/
Comment #36
bburg#2343127: Docblock fixes for core/lib/Drupal/Core/Database/Query. That's the bulk of them. Need to find a place to put core/lib/Drupal/Core/Database/Install/Tasks.php.
Comment #38
jhodgdonI'm closing this issue as Won't Fix. The problem is that the issue is too vast to fix in this type of patch. It is much better to have a targeted issue that just goes about fixing one type of problem at a time, throughout core, than an issue that ends up trying to fix everything. See https://www.drupal.org/core/scope for more information. Closing child issues too.