Warning

All patches are generated automatically, if the tests fail, do not attempt to fix it by hand, but create an issue against
the coder module cross linking the issues. The more we can fix in the coder
module, the better.

Part of #2571965: [meta] Fix PHP coding standards in core, stage 1.

Approach

We are testing coding standards with PHP CodeSniffer, using the Drupal coding standards from the Coder module. Both of these packages are not installed in Drupal core. We need to do a couple of steps in order to download and configure them so we can run a coding standards check.

Step 1: Remove the coding standard from the blacklist

Every coding standard is identified by a "sniff". For example, an imaginary coding standard that would require all llamas to be placed inside a square bracket fence would be called the "Drupal.AnimalControlStructure.BracketedFence sniff". There are dozens of such coding standards, and to make the work easier we have started by blacklisting all the sniffs. For the moment all coding standards that are not yet fixed are simply skipped during the test.

Open the file core/phpcs.xml.dist and remove the line that matches the sniff of this ticket (it's in the issue title). Make sure your patch will include the removal of this line.

Step 2: Install PHP CodeSniffer and the ruleset from the Coder module

Both of these packages are not installed by default in Drupal core, so we need to download them. This can be done with Composer, from the root folder of your Drupal installation:

$ composer require drupal/coder squizlabs/php_codesniffer

Step 3: Prepare the phpcs.xml file

Next we need to make a copy of the file phpcs.xml.dist (in the core/ folder) and save it as phpcs.xml. This is the configuration file for PHP CodeSniffer.

We have to configure the location of the Drupal coding standard ruleset from the Coder module that we just downloaded. To do this open the newly created file core/phpcs.xml. Find the line containing:

<rule ref="Drupal">

Change it to:

<rule ref="../vendor/drupal/coder/coder_sniffer/Drupal">

Or if you prefer the command line:

$ cd core/
$ cp phpcs.xml.dist phpcs.xml
$ perl -pi -e "s|ref=\"Drupal|ref=\"../vendor/drupal/coder/coder_sniffer/Drupal|" phpcs.xml

Step 4: Run the test

Now you are ready to run the test! From within the core/ folder, run the following command to launch the test:

$ ../vendor/bin/phpcs -p

This takes a couple of minutes. The -p flag shows the progress, so you have a bunch of nice dots to look at while it is running.

Step 5: Fix the failures

When the test is complete it will present you a list of all the files that contain violations of your sniff, and the line numbers where the violations occur. Go ahead and fix them all!

Comments

attiks created an issue. See original summary.

attiks’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new78.31 KB
~/.composer/vendor/bin/phpcbf --standard=/home/peter/.composer/vendor/drupal/coder/coder_sniffer/Drupal --sniffs=Generic.PHP.UpperCaseConstant --ignore=vendor,assets/vendor -p core/

Status: Needs review » Needs work

The last submitted patch, 2: i2572307-2.patch, failed testing.

attiks’s picture

Issue summary: View changes

Status: Needs work » Needs review

attiks queued 2: i2572307-2.patch for re-testing.

The last submitted patch, Generic.PHP_.UpperCaseConstant.diff, failed testing.

The last submitted patch, Generic.PHP_.UpperCaseConstant.diff, failed testing.

duaelfr’s picture

Issue tags: -Novice

As agreed between the mentors at Drupalcon, according to issues to avoid for novices, I am untagging this issue as "Beginner". This issue contains changes across a very wide range of files and might create too many other patches to need to be rerolled at this particular time. This patch has an automated way to be rerolled later so better to implement it after Drupalcon.

andriyun’s picture

Issue tags: +Needs reroll

Patch is outdated.
Need reroll

andriyun’s picture

Status: Needs review » Needs work
andriyun’s picture

Status: Needs work » Needs review
StatusFileSize
new77.97 KB

New patch created using phpcbf tool.

andriyun’s picture

Issue tags: -Needs reroll
attiks’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks for reroll

andypost’s picture

rtbc +1
checked with phpcbf 2.3.3 and get the same patch

tstoeckler’s picture

Status: Reviewed & tested by the community » Needs work

Even though it is pretty weird the ArchiveTar class is third-party code, so we should not modify it.

andypost’s picture

Status: Needs work » Reviewed & tested by the community

Leaving the file in this state makes no sense because it will break all work that happens to make core pass code review.
Suppose we should remove third-party into vendor and leave BC shim in separate issue.
Also we have nice example in Diff namespace when third-party code was converted to proper core-compatible units

attiks’s picture

#15 As said in #16, if it's third party, it should live in vendor, if we start adding exception, there's no end at the tunnel. If it stays it should follow the same standards.

andypost’s picture

catch’s picture

Status: Reviewed & tested by the community » Postponed
pfrenssen’s picture

Issue summary: View changes

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

andypost’s picture

Status: Postponed » Needs work

now the file bypassed so we can continue here

vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

Status: Needs work » Needs review
StatusFileSize
new84.24 KB

Hi guys,

rerolled and refixed with phpcbf

tstoeckler’s picture

Status: Needs review » Needs work

Apparently this is still a problem, because the patch includes changes to ArchiveTar.

vprocessor’s picture

core/lib/Drupal/Core/Archiver/ArchiveTar.php - changes removed from patch

vprocessor’s picture

Status: Needs work » Needs review
vprocessor’s picture

Assigned: vprocessor » Unassigned
alexpott’s picture

Status: Needs review » Needs work
  1. --- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
    +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
    

    This class is obeying symfony standards because it is a copy should have an

  2. +++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
    --- a/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
    +++ b/core/lib/Drupal/Core/DependencyInjection/YamlFileLoader.php
    

    See here

  3. +++ b/core/lib/Drupal/Core/Http/TrustedHostsRequestFactory.php
    --- a/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php
    +++ b/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php
    

    This file has a // @codingStandardsIgnoreFile at the top - shouldn't be changed.

  4. +++ b/core/lib/Drupal/Core/Template/TwigExtension.php
    --- a/core/lib/Drupal/Core/TypedData/Validation/ConstraintViolationBuilder.php
    +++ b/core/lib/Drupal/Core/TypedData/Validation/ConstraintViolationBuilder.php
    
    +++ b/core/lib/Drupal/Core/TypedData/Validation/ConstraintViolationBuilder.php
    --- a/core/lib/Drupal/Core/TypedData/Validation/ExecutionContextFactory.php
    +++ b/core/lib/Drupal/Core/TypedData/Validation/ExecutionContextFactory.php
    

    These also has a @codingStandardsIgnoreStart shouldn't be changed here.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new34.05 KB

I've added the suggested exclusions and re-run phpcs/phpcbf

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Nice, thank you! We are slowly slowly getting there

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 94a968e and pushed to 8.1.x and 8.2.x. Thanks!

  • alexpott committed 942c1cf on 8.2.x
    Issue #2572307 by vprocessor, attiks, andriyun, alexpott, pfrenssen: Fix...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.