Follow-up to #2707371: Fix several errors in the 'Drupal.Commenting.DocComment' coding standard
Problem/Motivation
Let's fix drupal/coder's sniffs in core.
We'll work on PSR2.Classes.PropertyDeclaration.ScopeMissing
, which requires that we declare scope for class properties and methods. Since this means replacing var
where we find it, we also end up fixing PSR2.Classes.PropertyDeclaration.VarUsed
.
Proposed resolution
Add drupal/coder and the phpcs package to your Drupal codebase:
# From Drupal root directory
$ composer require drupal/coder
$ ./vendor/bin/phpcs --config-set installed_paths DRUPALPATH/vendor/drupal/coder/coder_sniffer/
Modify the Drupal.Commenting.DocComment
errors to not be excluded from within core/phpcs.xml.dist
.
Run phpcbf from the core directory:
$ cd core
$ ../vendor/bin/phpcbf
This will fix some errors. Review what it did and fix problematic changes.
Run phpcs from the core directory in order to verify that no errors remain:
$ ../vendor/bin/phpcs -p
To review this issue
Install coder/phpcs as above.
Apply the patch.
Run phpcs from the core directory to verify that no errors remain.
$ cd core
$ ../vendor/bin/phpcs -p
Read the patch to check for errors.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#7 | 2706753_7.patch | 27.33 KB | Mile23 |
#4 | 2706753_4.patch | 38.42 KB | Mile23 |
Comments
Comment #2
Mile23Limited scope to
Drupal\Component
. We can file other issues for the rest of core, or just keep changing scope on this one piecemeal until done.Just a reminder that PSR2 tells us to not use var, and also to not use underscores at the beginning of class property names.
Comment #4
Mile23DiffOp properties needed to be public.
Comment #5
andypostthis needs to include sniffer into phpcs.xml.dist
current state for all core
Comment #6
pfrenssenComment #7
Mile23Updating issue summary to revert back to correct instructions.
Re: #5: That will be a big patch that will take a year to review, so I'm limiting the scope to
PSR2.Classes.PropertyDeclaration.ScopeMissing
, which also ends up fixingVarUsed
(sincevar
is the same aspublic
).We can rescope later or file a new issue with
Underscore
, which will require more cognitive resources to patch and review.Comment #8
dawehnerThat one is certainly internal, but yeah I guess its not this issue to discuss it.
Comment #9
alexpottI agree - this rule is good to implement and all we can do in this issue is make the properties public. Anything else is tricky and requires a lot of thinking.
Committed 7de3512 and pushed to 8.1.x and 8.2.x. Thanks!
Comment #11
Mile23If the property was declared using
var
, then it was always public by design.