Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've found this great utility class today. When using the dummy image generation function, I've found that the function parameters are documented wrong. As per phpDoc the type of $min_resolution and $max_resolution should be integers. The truth is however, that both parameters should be a string in the format '[width]x[height]'.
I'll provide a patch fixing the type and adding an appropriate description.
Comment | File | Size | Author |
---|---|---|---|
#14 | Screen Shot 2020-07-29 at 7.08.39 AM.png | 402.29 KB | tanubansal |
#6 | interdiff.txt | 1.11 KB | himanshu-dixit |
#6 | 2853777-6.patch | 889 bytes | himanshu-dixit |
#2 | fix_wrong_random_image_generation_doc-2853777-2.patch | 921 bytes | agoradesign |
Comments
Comment #2
agoradesign CreditAttribution: agoradesign commentedComment #3
agoradesign CreditAttribution: agoradesign commentedComment #4
mondrakeLooks good. Patch is doc change only.
Comment #5
xjmGood spot on the missing parameter documentation.
It should say "minimum" and "maximum" (which have slightly different meanings than "minimal" and "maximal"). We should use the full word instead of "min" and "max" later in the description as well.
The sentences are also kind of a run-on. We should split it into two sentences.
Finally, is there an existing description of data in this width x height format elsewhere in core that we should make it consistent with? The square brackets can confuse users since we are using them to denote "replace '[width]' with the number" but that is not actually clear or consistent. In general we should avoid such pseudo-delimiters because users can think they are part of the actual string format.
Actually this also calls into question why we do not allow passing separate min_width, min_height, max_width, and max_height parameters rather than this weird special string format. :) But that is out of scope for this issue, so would need to be discussed in a followup if anything.
Also, thinking about the scope of this issue in terms of: https://www.drupal.org/core/scope#coding-standards
This issue is adding missing parameter documentation. While missing parameter documentation is itself a coding standards error, adding that documentation needs to be done by writing it, which means understanding the concepts involved. So the current scope of this patch, limited to one concept, also makes sense.
However, we should make sure we're adding all the missing parameter documentation for this specific concept. Can we check whether there is any other missing documentation in the Random component? Writing that documentation together would work best.
Thanks @agoradesign!
Comment #6
himanshu-dixit CreditAttribution: himanshu-dixit as a volunteer commented@xjm Here is the new patch.
I found file which have existing description of data in this width x height format. The file is file.module :) .
Comment #7
agoradesign CreditAttribution: agoradesign commentedThe quick reactions to this tiny issue are awesome :) thx @xjm, @himanshu-dixit
I agree, that we should think of that parameters in general, as there are way better solutions. We could introduce value objects or at least use arrays with "width" and "height" parameters directly, as these are normally the way we work with image dimensions in Drupal afaik. E.g. there's ImageStyle::transformDimensions, where such an array is used.
@xjm: I've one interesting question left about issues like this one. As you can see in the issue's revision, I was rather unsure, which component to choose for this issue. On the one hand it's kinda documentation related, as phpdoc comments are part of the API documentation. But there are also valid arguments to choose the subsystems. I've changed it from "documentation" to "base system", after berdir answered to my question on IRC and gave me this advice
Comment #14
tanubansal CreditAttribution: tanubansal at Salsa Digital commentedTested via #6.
It's showing the added text. This can be moved to RTBC
Comment #16
quietone CreditAttribution: quietone as a volunteer commentedA description for these parameters was added in #3076644: Mistake in the comment documenting the "image" method of the "Random" utility class.. The text is different than what is in the patch, but the meaning is the same. Closing as a duplicate.