Problem/Motivation

In #3032686: Remove references to unused packages in Drupal 9's vendor hardening we added new test methods. To avoid blocking Drupal 9.0.0-rc1 the patch was committed with missing parameter and return type documentation.

Proposed resolution

See #3032686-31: Remove references to unused packages in Drupal 9's vendor hardening

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

longwave created an issue. See original summary.

hussainweb’s picture

Status: Active » Needs review
StatusFileSize
new1.19 KB

Here's an attempt.

kristen pol’s picture

Status: Needs review » Needs work

Thanks for the patch.

1) Looked at a few @return examples in the codebase and found no consistency. Some start with "An array..." or similar mention of "array" while others don't mention array at all. Since it's obvious it's an array, IMO it doesn't need to mention "array" explicitly. Using "list" seems fine as an alternative, or anything that is clear. That said, here's some feedback on the wording:

  1. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -66,6 +66,7 @@ public function testComposerTilde($path) {
        * @return array
    +   *   Paths of all composer.json files present in the Drupal core.
        */
       public function providerTestComposerJson() {
    

    Consider simplifying and using "List of" like the others, e.g.

    List of all composer.json file paths in Drupal core.

  2. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -126,6 +127,7 @@ public function testAllModulesReplaced() {
        * @return array
    +   *   List of scaffold files along with their source path and destination.
        */
       public function providerTestExpectedScaffoldFiles() {
    

    Consider being more explicit about the data in the array, e.g.

    List of scaffold files with destination path, source path, and named destination location.

    Or, an alternative without explicit parameter ordering that is just one line and has more generic wording:

    List of scaffold files with destination and source locations.

  3. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -267,6 +269,8 @@ public function testVendorCleanup($class, $property) {
        * @return array[]
    +   *   List of class properties which contain the packages whose vendor files
    +   *   are to be cleaned up.
        */
       public function providerTestVendorCleanup() {
    

    Consider simplifying, e.g.

    List of class properties that contain vendor package files to clean up.

2) Noticed a couple other things that could be updated in this file while adding these:

a) Missing periods.

   * @param string $destRelPath
   *   Path to scaffold file destination location
   * @param string $sourceRelPath
   *   Path to scaffold file source location
   * @param string $expectedDestination
   *   Named location to the destination path of the scaffold file

b) Missing @params.

  /**
   * Tests the vendor cleanup utilities do not have obsolete packages listed.
   *
   * @dataProvider providerTestVendorCleanup
   */
  public function testVendorCleanup($class, $property) {

3) Marking back to "Needs work" to consider 1 & 2.

mrinalini9’s picture

StatusFileSize
new2.36 KB
new2.32 KB

Update patch with the changes mentioned in #3.

kishor_kolekar’s picture

Status: Needs work » Needs review
kristen pol’s picture

Status: Needs review » Needs work

Thanks for the update. Not sure what happened to the arrays though. Maybe I'm missing something... tired and need sleep :)

  1. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -65,8 +65,8 @@
    +   * @return list
    

    list => array

  2. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -126,8 +126,8 @@
    +   * @return list
    

    list => array

  3. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -268,9 +272,8 @@
    +   * @return list
    

    list => array[]

mrinalini9’s picture

StatusFileSize
new2.28 KB
new1.01 KB

Hi,
Updated patch as per the changes mentioned in #6.

mrinalini9’s picture

Status: Needs work » Needs review
kristen pol’s picture

Thanks. I'll try to review tomorrow.

kristen pol’s picture

Thanks for the update.

1) Reviewed the interdiff in #7 and it addresses items in #6.

2) Patch applies cleanly to 9.0 and 9.1 but not 8.9.

[mac:kristen:drupal-8.9.x-dev]$ patch -p1 < 3133901-7.patch
patching file core/tests/Drupal/Tests/ComposerIntegrationTest.php
Hunk #1 succeeded at 52 (offset -14 lines).
Hunk #2 succeeded at 104 (offset -23 lines).
Hunk #3 succeeded at 149 (offset -23 lines).
Hunk #4 FAILED at 226.
Hunk #5 FAILED at 250.
2 out of 5 hunks FAILED -- saving rejects to file core/tests/Drupal/Tests/ComposerIntegrationTest.php.rej
[mac:kristen:drupal-8.9.x-dev]$ cd90
[mac:kristen:drupal-9.0.x-dev]$ patch -p1 < 3133901-7.patch
patching file core/tests/Drupal/Tests/ComposerIntegrationTest.php
[mac:kristen:drupal-9.0.x-dev]$ cd91
[mac:kristen:drupal-9.1.x-dev]$ patch -p1 < 3133901-7.patch
patching file core/tests/Drupal/Tests/ComposerIntegrationTest.php

3) Reviewed the code again and have one question.

+   * @param mixed $class
+   *   Name of the class where the property is defined.

Not sure why "mixed" is use. I do see it used in a few places but it's mostly string:

[mac:kristen:drupal-9.1.x-dev]$ grep -r "@param mixed \$class" . | wc
       4      20     279
[mac:kristen:drupal-9.1.x-dev]$ grep -r "@param string \$class" . | wc
      52     260    4466

e.g.

[mac:kristen:drupal-9.1.x-dev]$ grep -r "@param mixed \$class" .
./core/tests/Drupal/Tests/ComposerIntegrationTest.php:   * @param mixed $class
./core/lib/Drupal/Core/Entity/EntityTypeManagerInterface.php:   * @param mixed $class
./core/lib/Drupal/Component/Utility/Html.php:   * @param mixed $class
mrinalini9’s picture

Hi @Kristen Pol,
Thanks for the review. I have used 'mixed' for $class as I got the reference from the php.net official website, which is using the 'mixed' datatype for $class in ReflectionProperty class here.

kristen pol’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the explanation. Looks RTBC to me and patch applied to 9.0 and 9.1. Not sure if this would be backported.

xjm’s picture

Version: 9.0.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Needs work

Thanks for working on this -- always good to see our docs improved.

Usually, we like to see coding standards cleanups across all of core for a single rule, but for issues that add new parameter and return documentation, it makes sense to work just on one API (since one has to read and understand the code in order to document it). Therefore, I think the scope of this issue is correct.

  1. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -66,6 +66,7 @@ public function testComposerTilde($path) {
        * @return array
    
    @@ -126,6 +127,7 @@ public function testAllModulesReplaced() {
        * @return array
    

    If we're correcting parameter and return type docs for this class, we should also make the return doc type more specific than array. (Is it a string? Etc.)

  2. +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
    @@ -247,6 +249,10 @@ protected static function getContentHash($composerFileContents)
        * @dataProvider providerTestVendorCleanup
    +   * @param mixed $class
    +   *   Name of the class where the property is defined.
    

    There should be a blank line before the start of the @param section.

    Also, "Name of the class" sounds like a string. Is it the name of the class, or is it the class? (Looking at the code, I think it's the class).

    mixed is indeed very rarely used, but in this case seems accurate. Thanks @mrinalini9 for providing the reference there!

Moving to 8.8.x since documentation improvements are eligible for backport to the production branch. Thanks again!

xjm’s picture

+++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php
@@ -267,6 +273,7 @@ public function testVendorCleanup($class, $property) {
    * @return array[]
+   *   List of class properties that contain vendor package files to clean up.

Oh also, I think this isn't just a list. (If it were, it'd be string[][] or such. It's an array of arrays where the first element is the class and the second element is the property name. (I think). Also, it's not a list, it's an array of test cases.

So let's consider a little more what the docs should say here.

mrinalini9’s picture

Assigned: Unassigned » mrinalini9
mrinalini9’s picture

Assigned: mrinalini9 » Unassigned
mrinalini9’s picture

StatusFileSize
new1.48 KB

Patch for 8.8.x, please review.

For the above query:
1.

If we're correcting parameter and return type docs for this class, we should also make the return doc type more specific than an array. (Is it a string? Etc.)

For example:
providerTestComposerJson(): This function returns $data which is an array and it will contain the list of all composer.json file paths which I do have mentioned in the code doc. So, I think this should be fine.

mrinalini9’s picture

Status: Needs work » Needs review
kristen pol’s picture

Regarding #14, I was thinking of a list in a general sense not a "type" sense. Here are some examples already in use so these might help us reword the comments:

core/modules/user/src/PermissionHandler.php

   * @return array[]
   *   Each return permission is an array with the following keys:
   *   - title: The title of the permission.
   *   - description: The description of the permission, defaults to NULL.
   *   - provider: The provider of the permission.

core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php

     * @return array[]
     *   Returns data-set elements with:
     *     - aliases as returned by ContainerBuilder.
     *     - aliases as expected in the container definition.

core/lib/Drupal/Core/Test/JUnitConverter.php

   * @return array[]
   *   The results as array of rows in a format that can be inserted into the
   *   {simpletest} table of the results database.
nitesh624’s picture

Assigned: Unassigned » nitesh624
Status: Needs review » Needs work
nitesh624’s picture

StatusFileSize
new1.54 KB
new766 bytes

Replace @return array to @return array[] as per suggestion in #14 and #19

nitesh624’s picture

Assigned: nitesh624 » Unassigned
Status: Needs work » Needs review
kristen pol’s picture

To be clear, I didn't suggest changing the type in 19, I was simply providing some sample comments so we can figure out better documentation. Maybe the types should be changed but I haven't thought about that yet.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

kristen pol’s picture

Version: 8.9.x-dev » 9.1.x-dev

Note that patch still applies cleanly to 9.1.x.

janmejaig’s picture

I have tested , this document seems to be fine from my end and have added test for the 9.1.x .

tanubansal’s picture

RTBC + 1 from my end as well on 9.1

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

If we are fine with @return array[] then this looks good.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Actually, #14 and #19 have not been addressed. Reiterating: the current documentation is inaccurate -- it is not just a "list" -- and it is in scope for this issue to fix it.

xjm’s picture

#13.2 (second part beginning with "Also...") has not been addressed either.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

xjm’s picture

Status: Closed (outdated) » Needs work

The issue credits should be transferred over then :)

xjm’s picture

Also, the correct issue status for that is closed dupe. :)

smustgrave’s picture

@xjm closed issues get credit now so if they’re checked here they’ll get something.

If we move over then we should uncheck here too else we are giving double

smustgrave’s picture

Status: Needs work » Closed (duplicate)
smustgrave’s picture

StatusFileSize
new274.59 KB

screenshot

Uploading a screenshot to show.

xjm’s picture

Whoa! Did not know that. Thanks @smustgrave!