Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
comment.module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
13 Mar 2012 at 19:30 UTC
Updated:
29 Jul 2014 at 20:28 UTC
Jump to comment: Most recent file
Comments
Comment #1
tstoecklerNow that the philosophical debate has been decided as you point out, I think this is a Novice issue:
To-do list:
1. Go into core/modules/comment
2. Check all of the containing files for functions which receive $comment as a parameter
3. Add the type-hint to the parameter, i.e.:
Comment #2
underq commentedI tried to do a patch for this without forgot any $comment ;)
Comment #4
underq commentedI try new patch ;)
Comment #6
hansyg commentedHere's another shot at this patch
Comment #7
hansyg commentedBetter when its not empty ;)
Comment #8
hansyg commentedneeds review
Comment #10
tstoecklerThis should be:
I.e. the argument should be optional and the is_object() can be removed.
Otherwise looks good. :)
EDIT: Added the type-hint in my example code. *slapsforehead*
Comment #11
hansyg commentedMade the above changes and rerolled the patch, thanks for the help and review @tstoeckler
Comment #12
lars toomre commentedShouldn't type hinting also be done for the variables in the @param and @return directives in the docblocks? That way the documentation will indicate the expected type of $comment variable.
Comment #13
fagoGood progress!
yep, we also should add the class the do
Should be...
Comment #14
hansyg commentedAdded to the docblocks
Comment #15
klausiThis does not make sense. We have an array for $comments here.
should be "A comment entity.". Please check all occurences of "comment object".
Comment #16
pounardThere is no need to write "A comment object" nor a "A comment entity" here since the type hinting is self documenting. Just put the "@param Comment $comment" with no additional information is enough.
Comment #17
tstoecklerRe #16. That is incorrect. We have a standard that each parameter needs a description. If you disagree with that standard please open a new issue.
Comment #18
lars toomre commentedThe docblocks in comment.module seem to vary from documentation standards. For instance, comment_submit() is missing a @param directive and description. That needs to be added here. Additionally, when adding type hinting to one variable in a docblock, please do so for all of the @param variables.
Comment #19
fagoobjects needs to be removed.
objects needs to be removed.
Comment #20
hansyg commentedRerolled the patch with #19 @fago
Comment #21
hansyg commentedneeds review
Comment #22
lars toomre commentedThis does not make sense. It should be @param array $comments.
No @param directive here?? Appears @param Comment $comment is missing.
Ditto.
Ditto.
Comment #23
hansyg commentedChanges from #22
Comment #24
klausiThanks for working on this!
this is still wrong.
Comment #25
hansyg commentedWhoops, attached wrong patch. Corrected
Comment #26
aspilicious commentedThis is impossible. First it's an array than a Comment object.
This should brake the testbot somehow... So we aren't testing this?
Needs a line of explanation and has a trailing whitespace
Same
Comment #27
pounardWhy would it need an explaination, would you write "A comment object." ? Is "Comment $comment" not self-descripting enough?
That said, you're right about first points, it's an array not a Comment instance.
Comment #28
aspilicious commentedBecause it's our standard...
Comment #29
pounardThis particular piece of standard is about documentation, and this particular piece of documentation isn't needed anymore. I think in this case the standard doesn't fit the need anymore and must be revisited.
Comment #30
xjmRegarding #29: Each
@paramdoes need a description. Reference: http://drupal.org/node/1354#param-return-data-typeI'd agree that this:
is redundant and not so useful. However, instead of removing the parameter description, we should make it more useful and provide detail about the parameter. And, having a human-readable line explaining each parameter makes it easier to understand in the API docs.
That said, it's off-topic for this issue. We should follow the current standard as long as it is the standard. I suggested to pounard in IRC to open a separate coding standards issue to consider whether the standard should be changed if he thinks it should be.
Comment #31
pounardYes sorry for that, opened #1512338: Revisit Coding Standard about parameters documentation for discussion.
Comment #32
hansyg commentedI removed the extra whitespace from #26, I'd be happy to re-roll with additional changes not sure what needs to happen though.
Comment #33
aspilicious commentedSee #26, Comment should be array
Comment #34
berdirRe-rolled the patch with the things mentioned in #26 fixed.
By the way, Netbeans 7.2 has support for @param Comment[] $comments, which is way nicer than @param array $comments but that's something for another issue and day to look at ;)
@aspilicious: This can not be covered by tests as the hook example implementations are dead code, they are never executed and just serve as an example.
Comment #35
tstoecklerDarn it, found another one:
That should also be "array" instead of "Comment". (Or nothing, I've seen us type-hinting arrays elsewhere but I'm not sure it is a standard. Can't hurt though, I guess.)
Comment #36
berdirWell, it would help if I would not re-upload the old patch but my own.
Head -> Keyboard.
Comment #37
berdirComment #38
cosmicdreams commentedThis patch adds additional type hinting to:
comment.module
Also, there seems to be some function in comment.test that define a Comment object as a generic object. Is that right?
Comment #40
berdirLooks like there are some cases in comment.module where we're not loading comments as entities, for example:
That should be changed I guess but probably not in this issue.
Edit: Given that we have entity caching, I guess it's actually better and much simpler to do a simple comment_load($pid) and *then* check the status in the condition.
Comment #41
fagoWhy not just fix remaining problems in this issue? Tests probably won't pass anymore without having all uses fixed anyway.
@example from #40:
Looks like we could convert this directly to an entity_load() call making use of a condition for status, i.e.
Comment #42
aspilicious commentedfago isn't there a way to NOT write two lines for a single load? Do we have to go through comment_load_multiple?
Comment #43
berdirAs I said, I'd suggest this:
Using $conditions is deprecated and removes the possibility of getting the entity from cache and the status check is only a sanity check to not unpublish unpublished comments, so...
Comment #44
fagoNot when using conditions.. But, indeed #43 looks clean. (Actually, my example was wrong as we need to load the parent comment.)
Yep. #43++
Comment #45
tstoecklerI'll try to finish this one off now.
Comment #46
tstoecklerWell, that wasn't too hard. The code mentioned above in comment.pages.inc was responsible for most of those failures.
All previously failing tests pass locally now.
Comment #47
xjmPerhaps an inline comment here, e.g. "Load the parent comment."?
Edit: I take back what I said about scope; I previously failed to understand that this change is needed for tests to pass.
Comment #48
berdirThat is necessary to make the type hinting for comment_unpublish_action() work. Adding the type hint showed that we are in fact not passing an actual comment entity to that function.
That said, I initially suggested to do that in a follow-up issue as well. Just trying to explain why it was done.
Comment #49
tstoecklerAdded a comment per #47.
Comment #50
xjmAlright, assuming #49 passes the bot, I think this is ready. Thanks @Berdir and @tstoeckler.
Comment #51
catchThanks! Committed/pushed to 8.x.
Comment #52
adamdicarlo commentedPretty sure this is a bug:
Patch attached.
Comment #53
berdirD'oh.
I guess that means we don't have tests for this :)
Comment #54
tstoecklerOops, dammit, that was me. Sorry.
Will write a test for this tomorrow, if no one beats me to it.
Comment #55
berdir#52: drupal_1480866_52_comment_type_hint_follow_up.patch queued for re-testing.
Comment #56
xjmStill need the test coverage here, no?
Comment #57
tstoecklerYeah, I had totally forgotten about that, sorry.
Here we go.
Comment #58
aspilicious commentedLooks good to me...
Comment #59
xjmThe use of
t()here is inverted. The first string is translated incomment.module, so we need to uset()when we check for it. And thet()on the assertion message is not needed, though withassertText()I'd recommend just omitting that parameter. (The default message is useful.)Reference: http://drupal.org/simpletest-tutorial-drupal7#t
This is a minor cleanup, so another good novice task. When you create a new patch, be sure to upload both a test-only version and the complete patch, as in #57.
Comment #60
tstoecklerI adjusted the message so it is inline with the surrounding messages. I would suggest doing the clean-up mentioned in #59 in a separate issue. If we were to change this patch the resulting code would look pretty awkward, IMO.
Comment #61
berdirI went through that before as well, changed lines need to have a proper coding standard, doesn't matter if surrounding lines are wrong.
Comment #62
xjmAlso, the first problem (no
t()on the text we are testing for) is a straight-up bug. I would have just rerolled it myself otherwise.Comment #63
tstoecklerHow is that? We know the language of the site we are testing. So we might as well test for the exact string as it appears on the site.
Comment #64
sheise commentedHere are updated patches from #57 with the changes from #59.
Comment #66
aspilicious commentedActually this is rtbc (first in #64)
Comment #67
catchThanks. Committed/pushed to 8.x.
Comment #69
yched commentedFollowup : #1870790: Needless loading in comment_reply()