Problem/Motivation
API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
The docblock is incomplete: missing description, missing param and return.
There are several other methods that are similarly lacking in documentation.
In order to fix core coding standards in a maintainable way, all our coding standards issues should be done on a per-rule basis across all of core, rather than fixing standards in individual modules or files. We should also separate fixes where we need to write new documentation from fixes where we need to correct existing standards. This all should be done as part of #2571965: [meta] Fix PHP coding standards in core, stage 1. A good place to start is the child issues of #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard.
For background information on why we usually will not commit coding standards fixes that aren't scoped in that way, see the core issue scope guidelines, especially the note about coding standards cleanups. That document also includes numerous suggestions for scoping issues including documentation coding standards cleanups.
Proposed resolution
Scope this to just the add new documentation.
Remaining tasks
User interface changes
No
API changes
No
Data model changes
No
Original Summary:
API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
The docblock is incomplete: missing description, missing param and return.
There are several other methods that are similarly lacking in documentation. So, the scope of this issue is:
a) Make sure all methods on QueryInterface have first-line docs. Currently missing this:
- range()
- sort()
- accessCheck()
b) Make sure all methods on queryInterface have documentation lines with their param/return declarations (except @return $this, which has no documentation line). In addition to the methods in (a), methods needing work for this are:
- andConditionGroup
- orConditionGroup
- notExists (the @return should be @return $this)
- exists (the @return should be @return $this)
- condition (the @return should be @return $this)
- getEntityTypeId
| Comment | File | Size | Author |
|---|---|---|---|
| #85 | interdiff_2711739_83-85.txt | 909 bytes | ankithashetty |
| #85 | 2711739-85.patch | 9.4 KB | ankithashetty |
| #83 | interdiff_2711739_80-83.txt | 2.54 KB | ankithashetty |
| #83 | 2711739-83.patch | 9.4 KB | ankithashetty |
| #80 | 2711739-80.patch | 9.33 KB | init90 |
Comments
Comment #2
joelrguezaleman commentedHi Joachim,
Could you please expand a little further on:
Thanks in advance,
Comment #3
pushpinderchauhan commentedJust giving a try.
Comment #4
chgasparoto commented@er.pushpinderrana on your patch the description is still missing and you need a blank line before the return.
Edit: I accidentally deleted your file because when I did the request I got an error and I thought it was regarding my file in the uploaded files list.
So sorry about that.
Is there a way to rollback this action?
Comment #5
sushantpasteWith some additions and modifications.
Comment #6
jhodgdonHere is a review of the latest patch:
Please take a look at
https://www.drupal.org/node/1354#functions
The first line descriptions in this patch do not conform to our standards. The previous patch was better in this regard.
Needs another space of indentation.
Also we should fix the type. It should be int|null.
Also the first patch on this issue had:
That seems like very useful information about what NULL means. We should make sure this gets into the patch.
See previous note.
This should be changed to say:
@return $this
Should be @return $this
Comment #7
Sonal.Sangale commentedComment #8
Sonal.Sangale commentedModified the patch as per suggestion.
Comment #10
rakesh.gectcr@jhodgdon
How are you? Its been long time . By the by I am in new Orleans, If you are around would like to meet you.
I have applied the comments #6 you are mentioned.
Comment #11
hussainweb"If there *are*..."
Also, there should be a blank line between last @param and @return.
Comment #12
john cook commentedA couple of points for clarification:
I'm setting this back to needs work for this and #11.
Comment #13
snehi commented@John did not get you.
What you want to place here int|null|???
Done as mentioned in 11
Comment #14
john cook commentedI'll try to clarify a bit.
Is passing a $length of null different from passing 0; or should it be?
Does setting $length to NULL have any special meaning? eg passing NULL as $start has the special meaning of removing the range filter.
Possible options could be (there's probably others):
What returns NULL if there are no rows?
If it is this function that return NULL, "If there is no rows returns NULL" should be moved to the @return section. I don't think this is the case as it would break how QueryInterface is used.
If it describes the end result then it should be moved to before the @param section as it describes what happens at the
execute()stage. Again, I don't think this is the case either asexecute()has been defined as@return int|arrayso should never return NULL.The third option is to remove it as it does not describe anything about the function.
I hope this helps.
Comment #15
john cook commentedI have just noticed that there should be a short description of what the function does at the top of the docblock, so it should start like:
Comment #16
john cook commentedComment #17
Sonal.Sangale commentedAdded short description as per the suggestion.
Comment #18
jhodgdonThanks for the patches! It is looking better but still needs some work:
Can we make a better first line description for this? I think I don't like the word "enables" much. Maybe "Adds a range to" or "Defines the range of" or something like that?
This doesn't make sense to me. This function doesn't return NULL, it returns the query object. Besides, if it did return NULL, we would document that on the @return, not on the @param. So... what we need to document here is what passing in NULL for $length does to the query.
When you do @return $this, do not provide a description like "The called object" -- just take that line out.
See above note
See above note. There are several more of these in the patch. Please fix them all.
Comment #19
Sonal.Sangale commentedComment #20
Sonal.Sangale commentedComment #21
Sonal.Sangale commentedI have added change as per suggestion.
Below are the changes added for each comment:
1. Added description as "Defines the range of query."
2. I have not changed anything for this suggestion.
3. Removed the line "The called object."
4. Removed the line "The called object."
5. Removed the line "The called object."
I have also removed the line "The called object." from two funtions.
Comment #22
jhodgdonNot quite...
needs "the" before query.
Again, this is a *parameter*. Saying "If there are no rows returns NULL" doesn't make sense here.
What needs to be documented is what happens if you pass in NULL for $length.
Please also add a blank line before @return $this.
Well. Actually, these changes are out of scope for this issue, and should be removed. This issue is only about the range() function. Sorry for suggesting this fix in my earlier review. Let's just fix up range().
Comment #23
Sonal.Sangale commentedComment #24
Sonal.Sangale commentedI have added suggested changes.
Reverted all the changes of other functions except range() function.
Comment #25
jhodgdonHm, I'll try to say this again (for the third time).
In the @param line, it says int|null.
So, we need to document what it means if you pass in an int (this is done), and what it means if you pass in a NULL (this is not done).
So... Also I looked at QueryInterface, and there are two more methods with no documentation (similar to range()). These are:
- sort()
- accessCheck
There are also several other methods that are lacking documentation for either param or return:
- andConditionGroup
- orConditionGroup
- notExists (the @return should be @return $this)
- exists (the @return should be @return $this)
- condition (the @return should be @return $this)
- getEntityTypeId
I'm wondering if we should expand the scope of this issue to fix all of these problems, or file separate issues? Hm.... Given https://www.drupal.org/core/scope I think it would be appropriate to expand the scope to this entire file. So, updating title and issue summary.
Comment #26
Sonal.Sangale commentedComment #27
ashishdalviComment #28
ashishdalvi1. If $start and $length are NULL, then complete result is return.
2. If $start is not NULL and $length is NULL, then empty result set will be return.
I have given a try. Please review and share your thoughts.
Comment #29
jhodgdonMuch better, thanks! A few things to fix:
Between @return and @see, we need a blank line.
This is much clearer, thanks!
Some minor grammatical fixes -- better wording would be:
... then a complete result set will be generated.
... then an empty result set will be generated.
Note: Since the return value of this method is the class itself, let's not use the phrase "will be returned" here; instead, "will be generated".
Nice, thanks! This is good documentation. Very clear.
Should say
@return $this
Comment #30
ashishdalviHi jhodgdon,
Thank you so much for support.
I have worked on the mentioned mentioned above. Please review.
I have worked on following things.
Point 1, 2, 4 Done.
Point 5 :
1. Added data type names for param in condition(), exists(), notExists(), sort()
2. Added documentation line to accessCheck(). Remaining methods mentioned in issue summary exist documentation.
Thanks
Comment #31
ashishdalviComment #32
jhodgdonLooking better, thanks! Still a couple of things to fix:
Should be @return $this
It seems, given the @param description below, that this should be:
Enables or disables access checking for this query.
[note: should be Enables not Enable for the first-line description]
All @return lines [except @return $this or @return static] should have a documentation line below them. This is also the problem for orConditionGroup() and getEntityTypeId().
Comment #33
vinay15Comment #34
vinay15I have updated the patch as per your suggestions.
Comment #35
jhodgdonNot quite there yet:
Any time you see "the called object", it should be replaced by
@return $this
No, this does not return the called object. It returns a ConditionInterface, which is something else.
Same here.
Comment #36
rajeshwari10 commentedComment #37
rajeshwari10 commentedDone changes as per said.
Thank!!
Comment #38
jhodgdonAlmost there! One more suggestion on the new documentation added in this latest patch:
Can we reword this (and the similar OR documentation line)... it seems kind of awkward and a bit misleading. Something like:
A condition object whose conditions will be combined with AND.
Comment #39
hussainwebChanging as per suggestion in #38.
Comment #40
jhodgdonHooray for the QueryInterface having actual documentation! Thanks!
Comment #41
xjmThank you for your work on cleaning up Drupal core's code style!
In order to fix core coding standards in a maintainable way, all our coding standards issues should be done on a per-rule basis across all of core, rather than fixing standards in individual modules or files. We should also separate fixes where we need to write new documentation from fixes where we need to correct existing standards. This all should be done as part of #2571965: [meta] Fix PHP coding standards in core, stage 1. A good place to start is the child issues of #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard.
For background information on why we usually will not commit coding standards fixes that aren't scoped in that way, see the core issue scope guidelines, especially the note about coding standards cleanups. That document also includes numerous suggestions for scoping issues including documentation coding standards cleanups.
Contributing to the overall plan above will help ensure that your fixes for core's coding standards remain in core the long term.
In the case of this issue, these are the lines of new documentation:
So, the attached patch adds only those changes, plus two additional changes:
(optional)at the beginning of the textual description. https://www.drupal.org/node/1354#paramnullonly forrange()is so confusing and strange that I included correcting that as well; otherwise the descriptions for those parameters don't even make sense.The rest of the fixes for adding and correcting data types (as well as the fix to indentation) can happen as part of the respective child issues of the meta.
Comment #42
yesct commentedI think I understand the new scope of this issue.
I'll review it.
Comment #43
yesct commentedWe dont usually use "legal" values
ag "^[ ]*\*.*value.*[\"]" core | grep -i legalcore/lib/Drupal/Core/Database/Query/SelectInterface.php:404: * The direction to sort. Legal values are "ASC" and "DESC". Any other valueor
ag "^ *\* *.*[Ll]egal value" core"allowed" is more the norm in core
ag "^[ ]*\*.*value.*[\"]" core | grep -i allowedor
ag "^ *\* *.*[Aa]llowed value" coreSo I'm going to change it to allowed values.
There are two sentences that can be line wrapped. Going to do that.
https://www.drupal.org/node/1354#drupal
"Lines containing comments (including docblocks) must wrap as close to 80 characters as possible without going over, with a few exceptions (noted in the Tag Reference below)."
-------------
I also looked to see if " or ' was more common for quotes to use in comments to note allowed values and found both... so I dont see a clear decisions for quotes. Leaving those at ".
I also looked at this section. Cause it seemed weird to talk about both start and length under only length... but it doesn't make sense before @param and it is against coding standards to put it between @param and @return... and $start was talked about first... so I think this is ok.
phpcs -s -p --standard=./core/phpcs.xml.dist --extensions='php,module,inc,install,test,profile,theme,js,css,info,txt' core/lib/Drupal/Core/Entity/Query/QueryInterface.phpwhich runs just the standards that are checked in core, and there are no violations.
------
So the interdiff is just a change from Legal to allowed, and wrapping a line. The rest of the changes are good. rtbc.
Comment #44
yesct commentedforgot to change status to rtbc.
A follow up issue to fix QueryInterface::sort()
so that it really only allows the two values and throws an error if another value for the direction arg is given.
The way it is now is brittle.
Mis-spell DESC as DSC or something and it will sort ascending.
Comment #45
alexpottThis is a little complex. It looks like different implementations do different things.
\Drupal\Core\Database\Driver\pgsql\Select::orderBy() does
\Drupal\Core\Database\Query\Select::orderBy does
\Drupal\Core\Config\Entity\Query\Query::execute() does
\Drupal\Core\Entity\KeyValueStore\Query\Query::execute() does
Tricky...
Comment #46
yesct commentedadding dev days tag, and also taking off novice, since this is currently tricky to know what the next step is.
some ideas for way forward
take out the "fix" to the docs for the sort order and make a separate issue to... make the implementations consistent? (but that would be a BC break and need to go into 9.x https://www.drupal.org/core/d8-allowed-changes)
or change the docs to say "oops. our different implementations do different things. go look at their docs."?
or maybe the implementations dont document.. themselves
side note:
$direction = $sort['direction'] == 'ASC' ? -1 : 1;
could really benefit from a const
So first I guess we need to
verify what the actual behavior of those implementations is when neither allowed value is given (what they actually default to)
and
check the docs on the implementations for their own accuracy
Comment #47
alexpottMarking 'needs work' for #45 and #46
Comment #54
krzysztof domański1. I have updated the other missing docs.
2. I created a follow-up #3079258: Make SQL direction default behavior more consistent when an unknown direction is passed for #45.
Comment #55
Kamil Serafin commentedComment #56
dpiChanges looking good,
Feedback, especially updating documentation:
I wonder if mixed should be converted to the scalars, since NULL is defined. Not sure about this.
We should document what NULL does.
Docs should be updated, with NULL behaviour last.
We should document what NULL does.
NULL should be documented
Documentation indicates values other than int are valid.
Mechanisms of automatic calculation should be summarised. or @see'd
While we're in the neighborhood, CS requires a blank line between @return and @see
Comment #58
init90The patch tries to address most points from #56(except point 7). It's still far from ideal but contains some progress.
Comment #59
john cook commentedMost of the points from comment #56 except for point 7 (repeated here for clarity):
Mechanisms of automatic calculation should be summarised. or @see'd
Because this still needs to be documented I'm setting to needs work.
Comment #60
init90Here is an attempt to address point 7 from #56.
Comment #61
alex liannoy commented@init90, I am not the native speaker, but I would change it text to:
"If not provided, one is automatically calculated by incrementing the every next pager element value."
Otherwise, looks good to me.
Comment #62
init90Thanks, @alex-liannoy. I've updated the patch according to your suggestion.
Comment #63
dpacassiThe given
$valuecan also be abooleanorinteger.E.g.:
$query->condition('status', NodeInterface::PUBLISHED);where
NodeInterface::PUBLISHEDhas an integer value of1.Comment #64
dpacassiActually the
$valuefield can also be of anDrupal\Core\Entity\Query\ConditionInterfaceinstance.I guess it's better to mark the field as
mixedthen.Comment #65
dpacassiUpdated patch with an improved comment.
Comment #67
davidhernandezrerolling
Comment #68
tanubansal commentedPatch #67 changes are visible on 9.1
Comment #70
longwaveI think we can say
string|\Drupal\Core\Condition\ConditionInterfacehere.Comment #71
ayushmishra206 commentedComment #72
ayushmishra206 commentedRerolled patch #67 for 9.2.x, Made the change suggested in #70. Added the interdiff to reflect the same. Please review, thanks.
Comment #73
ayushmishra206 commentedSeems like the change was missed in the last patch.
Comment #74
longwaveComment #75
suresh prabhu parkala commentedUpdated as mentioned in #74. Please review.
Comment #76
longwaveThanks! A few minor points:
Needs a space before ( i.e. "operators ("
This part of the reroll looks incorrect, I think we should just keep the ConditionInterface line.
Again this looks wrong, the ConditionInterface reference was correct.
Comment #77
vsujeetkumar commentedAddressing #76, Please have a look and advise.
Comment #78
abhijith s commentedApplied patch #77.The problems mentioned in #76 are rectified in this patch.
Comment #79
longwaveI still think these two are wrong - these classes don't exist.
Comment #80
init90Seems like
andConditionGroupandorConditionGroupnever existed as separate classes and reference to them was incidentally added in #1801726: EntityFieldQuery v2. I have changed that references to interface methods with the same names.Comment #81
longwaveThanks, this is looking good now.
Comment #82
larowlanThis is looking really good, appreciate the effort folks have gone to here, especially those for whom English is their non native language, it's hard enough getting this right in your native language let alone a second one 🧠💪
I think this should be 'Defaults to NULL' not 'Default to NULL'
I'm not sure what we're trying to say here. Perhaps this could read 'These operators ignore $value, for that reason it is recommended to use a $value of NULL for clarity' ?
We should also point people to
existsandnotExistsmethods via @see as they are preferred to IS NULL and IS NOT NULL when it comes to entity queries. (And in my experience those methods work first time, whereas I've always had trouble getting the right combination for IS NULL and IS NOT NULL)I'm not sure what this means, suggest removing the word 'every' perhaps?
I'm not sure what 'will be converted' means, can we elaborate on what it will be converted to or how it will be converted?
Thanks again for working on this
Comment #83
ankithashettyUpdated the patch in #80 addressing #82.1, #82.2, #82.3 and #82.4. Kindly review.
To answer #82.4, ideally it should be
`Any other value will be converted to "ASC"`, but I don't see that happening in any of the classes implementingQueryInterface. An issue has already been created to address this #3079258: Make SQL direction default behavior more consistent when an unknown direction is passed, where the code along with the doc comment for/core/lib/Drupal/Core/Entity/Query/QueryInterface::sort()needs to be updated.Thank you!
Comment #84
longwaveThanks for updating this, one more nit and then hopefully we're done:
This is now over 80 characters and needs rewrapping.
Comment #85
ankithashettyUpdated patch in #83 addressing #84. Thanks!
Comment #86
longwaveThanks! All review points have been addressed. I agree that solving the ASC/DESC issue can be deferred to that other issue and that the comment here is good enough for now.
Comment #88
catchCommitted 9c9c981 and pushed to 9.2.x. Thanks!