Problem/Motivation

See #2909372-14: Enable 'Drupal.Commenting.VariableComment.MissingVar' coding standard for the reason why this child issue was created and #2909364: [meta] Fix 'Drupal.Commenting.VariableComment' coding standard for general instructions about working on Drupal.Commenting.VariableComment coding standard errors.

Steps to reproduce

Proposed resolution

Fix errors found by Drupal.Commenting.VariableComment.MissingVar for parameters that do not have a default value.

Remaining tasks

MR 3689 is for 11.x
Review
Commit

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-2924782

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

zaporylie created an issue. See original summary.

zaporylie’s picture

Issue summary: View changes
ioana apetri’s picture

Assigned: Unassigned » ioana apetri

I will work on this.:)

zaporylie’s picture

@yo30 - please check patch in #2909372-12: Enable 'Drupal.Commenting.VariableComment.MissingVar' coding standard. We have most of the work in place already, you can just extract part which is in the scope of this issue. Please note, that two co-child issues have landed already so you'll probably experience merge conflict, thus patch would have to be re-rolled.
In order to sniff for code errors violating Drupal.Commenting.VariableComment.MissingVar coding standard you must remove ignored rule from core/phpcs.xml.dist

ioana apetri’s picture

I checked the files for this error violation Drupal.Commenting.VariableComment.MissingVar and seems to be fine.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

zaporylie’s picture

Assigned: ioana apetri » Unassigned

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

osman’s picture

Status: Active » Needs review
StatusFileSize
new25.6 KB
mfernea’s picture

Status: Needs review » Needs work

I only see a missing change in core/tests/Drupal/Tests/Component/PhpStorage/MTimeProtectedFileStorageTest.php for:

  /**
   * {inheritdoc}
   */
  protected $defaultCacheContexts = ['languages:language_interface', 'session', 'theme', 'url.path', 'url.query_args', 'user.permissions', 'user.roles:authenticated'];
osman’s picture

Are you by any chance referring to core/modules/media/tests/src/Functional/MediaTranslationUITest.php actually?

+++ b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
@@ -16,6 +16,8 @@ class MediaTranslationUITest extends ContentTranslationUITestBase {
 
   /**
    * {inheritdoc}
+   *
+   * @var array
    */
   protected $defaultCacheContexts = [
     'languages:language_interface',
@@ -29,6 +31,8 @@ class MediaTranslationUITest extends ContentTranslationUITestBase {
mfernea’s picture

Yes, indeed.

zaporylie’s picture

Issue tags: +DevDaysTransylvania

#11 is already addressed in the base class the docblock is inherited from (ContentTranslationUITestBase) so, IMHO, doesn't need to be addressed here.

/**
   * Default cache contexts expected on a non-translated entity.
   *
   * Cache contexts will not be checked if this list is empty.
   *
   * @var string[]
   */
  protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'url.query_args:_wrapper_format', 'user.permissions'];
mfernea’s picture

The best solution here is {@inheritdoc}, but that means we only need to add the "@". So, it's not part of this issue.

mfernea’s picture

Status: Needs work » Reviewed & tested by the community

Adding the correct status.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I disagree with @mfernea - if the inheritdoc is broken we should be fixing it here because then we don't need to add the @var at all.

Also we should be more specific if we can be i.e. use @var string[] etc...

I made a start of reviewing for this... but all the fixes here need checking...

  1. --- a/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    +++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
    
    @@ -54,6 +54,8 @@ class DateTimePlus {
    +   *
    +   * @var array
    
    @@ -113,6 +115,8 @@ class DateTimePlus {
    +   *
    +   * @var array
    

    @var string[]

  2. +++ b/core/lib/Drupal/Core/Access/CheckProvider.php
    @@ -38,6 +38,8 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
    +   *
    +   * @var array
    

    @var string[]

  3. +++ b/core/lib/Drupal/Core/Cache/MemoryBackend.php
    @@ -23,6 +23,8 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
    +   *
    +   * @var array
    
    +++ b/core/lib/Drupal/Core/Cache/PhpBackend.php
    @@ -28,6 +28,8 @@ class PhpBackend implements CacheBackendInterface {
    +   *
    +   * @var array
    

    @var object[]

  4. +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php
    @@ -68,6 +68,8 @@ class Connection extends DatabaseConnection {
    +   *
    +   * @var array
    

    string[]

  5. +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php
    @@ -52,6 +54,8 @@ class Connection extends DatabaseConnection {
    +   *
    +   * @var array
    

    string[]

  6. +++ b/core/lib/Drupal/Core/Render/Element/HtmlTag.php
    @@ -37,6 +37,8 @@ class HtmlTag extends RenderElement {
    +   *
    +   * @var array
    

    string[]

  7. +++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
    @@ -60,6 +60,8 @@ class UrlGenerator implements UrlGeneratorInterface {
    +   *
    +   * @var array
    

    string[]

  8. +++ b/core/lib/Drupal/Core/Test/FunctionalTestSetupTrait.php
    @@ -43,6 +43,8 @@ trait FunctionalTestSetupTrait {
    +   *
    +   * @var array
    

    string[]

  9. +++ b/core/modules/comment/tests/src/Functional/CommentTranslationUITest.php
    @@ -30,6 +30,8 @@ class CommentTranslationUITest extends ContentTranslationUITestBase {
    +   *
    +   * @var array
    

    string[]

  10. +++ b/core/modules/file/tests/src/Functional/Update/FileUpdateTest.php
    @@ -13,6 +13,8 @@ class FileUpdateTest extends UpdatePathTestBase {
       /**
        * Modules to enable after the database is loaded.
    +   *
    +   * @var array
        */
       protected static $modules = ['file'];
    

    Change to {@inheritdoc}

  11. +++ b/core/modules/media/tests/src/Functional/MediaTranslationUITest.php
    @@ -16,6 +16,8 @@ class MediaTranslationUITest extends ContentTranslationUITestBase {
       /**
        * {inheritdoc}
    +   *
    +   * @var array
        */
       protected $defaultCacheContexts = [
    
    @@ -29,6 +31,8 @@ class MediaTranslationUITest extends ContentTranslationUITestBase {
       /**
        * {inheritdoc}
    +   *
    +   * @var array
        */
       public static $modules = [
    

    This change looks unnecessary the @var is on the parent.

  12. +++ b/core/modules/migrate/tests/src/Unit/process/UrlEncodeTest.php
    @@ -15,6 +15,8 @@ class UrlEncodeTest extends MigrateTestCase {
       /**
        * @inheritdoc
    +   *
    +   * @var array
        */
       protected $migrationConfiguration = [
    

    Should be inheriting.

  13. +++ b/core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
    @@ -13,6 +13,8 @@ class DrupalSqlBaseTest extends MigrateTestCase {
       /**
        * Define bare minimum migration configuration.
    +   *
    +   * @var array
        */
       protected $migrationConfiguration = [
    

    Use inheritdoc

  14. +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php
    @@ -18,6 +18,8 @@ class Drupal6SqlBaseTest extends MigrateTestCase {
       /**
        * Define bare minimum migration configuration.
    +   *
    +   * @var array
        */
       protected $migrationConfiguration = [
    

    inheritdoc

  15. +++ b/core/modules/migrate_drupal/tests/src/Unit/source/d6/VariableTranslationTest.php
    @@ -18,6 +18,8 @@ class VariableTranslationTest extends MigrateSqlSourceTestCase {
       /**
        * Define bare minimum migration configuration.
    +   *
    +   * @var array
        */
       protected $migrationConfiguration = [
    
    @@ -33,6 +35,8 @@ class VariableTranslationTest extends MigrateSqlSourceTestCase {
       /**
        * Expected results from the source.
    +   *
    +   * @var array
        */
       protected $expectedResults = [
    
    @@ -49,6 +53,8 @@ class VariableTranslationTest extends MigrateSqlSourceTestCase {
       /**
        * Database contents for tests.
    +   *
    +   * @var array
        */
       protected $databaseContents = [
    

    {@inheritdoc}

mfernea’s picture

Indeed, I was wrong. I thought it should be fixed in a sibling issue, but it's not. Let's fix it here.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

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.

spokje’s picture

Assigned: Unassigned » spokje

spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review

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.

spokje’s picture

Rebased MR on 9.3.x.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Coding standards
spokje’s picture

Assigned: Unassigned » spokje
spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review

Thanks @quietone for the review.

- Merged the latest 9.3.x into the MR.
- Found, added and fixed new offender.
- Resolved all but one thread.

spokje’s picture

Version: 9.3.x-dev » 9.4.x-dev
spokje’s picture

  • Rebased MR on 9.4.x-dev
  • Merged latest commits
quietone’s picture

I was still concerned that the scope of the patch is greater than the Issue Summary so did some research.

I have gone back to look at the parent and the siblings of this issue. I understand that this has been split into child issues on the recommendation xjm made 4 years ago. However, if the missing @var work is being split into several issues then the sniff can't be added by each sibling. And that is true, the siblings are not enabling the sniff. In this case, it is the parent that will enable the sniff and pick up what was not covered by the other siblings or crept into the code base.

So, I think the sniff needs to be removed and changes to @var that are not for 'arrays that provide default values' need to be removed. That will result in two smaller patches and thus easier to review.

However, we are already here and this is the last sibling, maybe it is more efficient to continue on here? I can't decide.

I'd like another opinion.

spokje’s picture

Thanks @quietone.

Seeing this is indeed the last child, and the fact that the MR "only" (I use only lightly here, but most Coding Standards issues I've worked on included much more changes) contains ~50 changes, and the fact that splitting this issue up into 2 sub-issues would take a some time, I personally am a fan of:

- Not splitting this issue up: Mostly to save time, in my tiny mind, the review time will stay the same in either 1 or 2 issues. The main issue I see is that a bigger issue will take more time before it's reviewed and committed by a Core Committer/
- Enabling the sniff here: Don't do it here but do it in the parent issue opens the chances of new offenders creeping in. Seeing it's the last child issue, I can't see an advantage in enabling it in the parent, besides it being fully "according to the rules".

So, solely based on efficiency I'm a non-split advocate for this one. Willing to be convinced otherwise.

drops EUR 0.02

quietone’s picture

I too am not keen on someone spending time splitting this up, so let's move forward with this patch, unless a committer disagrees.

I'll work on reviewing the MR today.

quietone’s picture

Title: Missing @var annotation for arrays that provide default values » Fix remaining VariableComment.MissingVar annotation
Issue summary: View changes

Update IS

spokje’s picture

Thanks @quietone.

Needing a second opinion about the two remaining @var string[] or @var string[][] threads.

quietone’s picture

Since I got confused about string[] and string[][] I asked in #bugsmash. Everyone agreed with the answer posted by kim.pepper (abbreviated)

from what i've seen, string[] can be either a list or associative:

    ['a', 'b', 'c']  OR
    [ 'a' => 'a, 'b' => 'b', 'c' => 'c']

string[][] would imply:

    ['a' => ['a', 'b'], b => ['c']]

Some responses also pointed out that the properties should be documented as well. I think that is the goal but we need to get there incrementally. This is just a step and prevents MissingVar from happening in the future.

I am going to review the MR now using the above definition.

quietone’s picture

Status: Needs review » Needs work

This time I went through the entire MR. I noted some things that are really out of scope. I should go back and resolve that but I need a break from this. Maybe tomorrow.

Setting to NW for the review of the MR.

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.

quietone’s picture

Title: Fix remaining VariableComment.MissingVar annotation » Enable sniff Drupal.Commenting.VariableComment.MissingVar
Category: Bug report » Task

Implementing sniffs are not bugs, they are tasks.

The failing test is not related to these changes, I am retesting.

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

Title: Enable sniff Drupal.Commenting.VariableComment.MissingVar » Fix remaining missing @var annotation that do not have a default value
Issue summary: View changes
Status: Needs work » Needs review

Changing the scope to make the change set smaller and easier to review.

quietone’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed the updates and changes appear correct.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

MR has merge conflicts.

quietone changed the visibility of the branch 2924782-missing-var-annotation to hidden.

quietone’s picture

Status: Needs work » Needs review

Rebased

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

quietone’s picture

Rebased and changed the instance in \Drupal\FunctionalTests\Update\UpdatePathTestBase to an {@inheritdoc}.

nod_ made their first commit to this issue’s fork.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

MR has a merge conflict and a question about the change to phpcs.xml.dist.

Also, the release note snippet in the IS seems wrong, as we are enabling that in the parent issue - not here.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review

Rebased and had to fix mistakes so setting to NR.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems good.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think we should be changing phpcs.xml to enable the rule no? Also I think removing the @var when there is a default value is really odd.

quietone’s picture

Status: Needs work » Needs review

@alexpott, thanks for the review.

Unfortunately, the scoping on this is unusual and the sniff can't be modified to cover this set of changes. However, I did enable the sniff for some file patterns. In the parent issue the remaining 50 errors in 32 files can be fixed and the sniff enable for all files.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

quietone’s picture

Status: Needs work » Reviewed & tested by the community

A straightforward rebase so restoring RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

This change confuses me because it's removing @var from stuff... also if I only apply the changes to the phpcs.xml.dist and run PHPCS the other error that's found is:

> phpcs --standard=core/phpcs.xml.dist --parallel="$( (nproc || sysctl -n hw.logicalcpu || echo 4) 2>/dev/null)" -- 'core'

FILE: /Volumes/dev/drupal/core/modules/block/tests/src/Kernel/NewDefaultThemeBlocksTest.php
-------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------
 37 | ERROR | Missing @var tag in member variable comment
-------------------------------------------------------------------------------------------

Time: 26.72 secs; Memory: 12MB

So the rule changes are not covering the changes being made here.

quietone credited andriyun.

quietone credited shkiper.

quietone credited xjm.

quietone’s picture

Title: Fix remaining missing @var annotation that do not have a default value » Enable 'Drupal.Commenting.VariableComment.MissingVar' coding standard
Status: Needs work » Needs review

The 'Overview' in the MR does not reflect the actual changes and it quite confusing. There were also truly unexpected errors on my part that I can't quite figure out how they happened. So, I started over and it turns out that this can now enable the sniff as well.

So, I am closing the parent as a duplicate, changing the title and moving credit.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All the documentation changes look good to me.
The remark of @alexpott has been addressed.
For me it is RTBC.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Couple of minor issues in the MR, also needs a reroll

Thanks for working on this.

kul.pratap made their first commit to this issue’s fork.

kul.pratap’s picture

Status: Needs work » Needs review
quietone’s picture

Status: Needs review » Needs work

@kul.pratap, Welcome to Drupal! Thanks for working on this. I made a few comments in the MR. Also, This is failing the pre commit checks. It is good practice to Run core development checks locally before submitting a change.

There have been recent commits that are causing more errors. I don't think the sniff can be enabled here. This will have to go back to doing a subset of files. I'll look into that now.

kul.pratap’s picture

@quietone Thank you for the feedback. I will review the comments in the MR and address them.

quietone’s picture

Title: Enable 'Drupal.Commenting.VariableComment.MissingVar' coding standard » Fix 'Drupal.Commenting.VariableComment.MissingVar' outside of Plugins

@kul.pratap, thanks. I just added another change to exclude files in 'Plugin' directories. That should help here.

Updating title for the new scope.

I'll work on an issue for the changes in the 'Plugin' directories.

kul.pratap’s picture

@quietone Should I resolve the unresolved issues in the MR as mentioned by you?

quietone’s picture

@kul.pratap, Thanks for asking! The suggested changes to phpcs.xml.dist should exclude the files that have just started to cause violations from being checked by phpcs. Without those being checked that will bet this back on track to where only the feedback from larowlan and myself need to be resolved.

The files that have just started to cause the violations are going to be fixed in the parent issue, along with enabling the sniff on all of core. I've already set that up and postponed that on this issue.

I hope that all make sense.

kul.pratap’s picture

Status: Needs work » Needs review

@quietone Please review.

smustgrave’s picture

Status: Needs review » Needs work

Pipeline has errors. Would recommend verifying that everything passes before putting into review please.

quietone’s picture

@kul.pratap, thanks for reverting those changes.

I was concerned that the number of files to change would make the MR here larger that our recommended size. So, I've updated phpcs.xml.dist to ignore Plugin files, which agrees with the title here. There are still about 25 files to edit.

quietone’s picture

Status: Needs work » Needs review

More changes for recent commits.

smustgrave’s picture

Status: Needs review » Needs work

Tried to resolve some threads but things got messy at some point. Left most open.

quietone’s picture

Status: Needs work » Needs review

This is at least the second time I have had the gitlab MR UI disagree with the changes that are actually in the branch. It is very confusing.

We need to agree to the change for core/tests/Drupal/FunctionalTests/Installer/InstallerExistingConfigTestBase.php.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

quietone’s picture

Status: Needs work » Closed (duplicate)

I meant to re-scope this but I accidentally created a new issue to divide up the work for this sniff.

I am closing as a duplicate an transferring credit to #2909372: Enable 'Drupal.Commenting.VariableComment.MissingVar' coding standard