Problem/Motivation

While it doesn't seem to be a huge problem, the PHP 7.3 change where a "continue" statement inside a "switch" statement has the same effect as a "break" has shown up in core and a few modules, so it might be worth adding a rule for this.

Proposed resolution

Add a dependency on slevomat/coding-standard so we can leverage some of their useful sniffs. For example:

Remaining tasks

https://github.com/pfrenssen/coder/pull/147

User interface changes

API changes

Data model changes

Release notes snippet

Comments

DamienMcKenna created an issue. See original summary.

DamienMcKenna’s picture

Issue tags: +PHP 7.3
Liam Morland’s picture

Title: Add PHP 7.3 test to check for "continue" instead "switch" statement » Add PHP 7.3 test to check for "continue" inside "switch" statement
pfrenssen’s picture

alexpott’s picture

Title: Add PHP 7.3 test to check for "continue" inside "switch" statement » Add dependency on slevomat/coding-standard
Issue summary: View changes
alexpott’s picture

Issue summary: View changes

Added link to PR to issue summary - https://github.com/pfrenssen/coder/pull/147

klausi’s picture

Status: Active » Needs work

Checked the pull request and left a comment there, I think we should do more than just adding the dependency.

  • alexpott authored 929d7d4 on 8.3.x
    feat(slevomat): Add dependency on slevomat coding standard to include...
klausi’s picture

Status: Needs work » Fixed

Committed, thanks! This bumps Coder's PHP minimum version to 7.1, but I think that is fine (PHP 7.0 has been end of life for 3 years now). Users with older PHP versions can still use the previous Coder version.

Please open new issues to enable and configure more sniffs for the selvomat coding standard. Please also add minimal test cases to bad.php so that we know the inclusion actually works.

m.stenta’s picture

We use PHP Codesniffer + Coder in our automated testing workflow to check coding standards, and today phpcs has started failing with:

Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist

I found this issue while trying to investigate... is it related? Has anyone else encountered this?

jeqq’s picture

Facing the same issue: ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist

jribeiro’s picture

The same error as #10 and #11

Aron Novak’s picture

Experimenting with

COMPOSER_MEMORY_LIMIT=-1 composer global require slevomat/coding-standard:^7.0
COMPOSER_MEMORY_LIMIT=-1 composer global require drupal/coder:^8.3.10
phpcs --config-set installed_paths ~/.config/composer/vendor/drupal/coder/coder_sniffer,~/.config/composer/vendor/slevomat/coding-standard

No luck so far.

Arkener’s picture

This issue occurs when the Coder standards are loaded, but the Slevomat standard isn't. We're currently using dealerdirect/phpcodesniffer-composer-installer to automatically set the installed_paths on Composer install. When using Composer 2.2 or higher, Composer will ask for your permission to allow this plugin to execute code. For this plugin to be functional, permission needs to be granted. Which will result in the following config in the composer.json

"config": {
    "allow-plugins": {
        "dealerdirect/phpcodesniffer-composer-installer": true
    }
},

This issue will also occur when phpcs --config-set installed_paths is executed after the composer install without including the Slevomat standard, as it will overwrite the automatically set installed_paths.

The workaround of #13 will also fix this issue, but make sure to use absolute paths, as ~ will only work on the first standard. So taking the previous example, use:

phpcs --config-set installed_paths 
 /home/lorem/.config/composer/vendor/drupal/coder/coder_sniffer,/home/lorem/.config/composer/vendor/slevomat/coding-standard
aczietlow’s picture

Just confirming that #13 and #14 worked to resolve the issue identified in #10

ERROR: Referenced sniff "SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator" does not exist

1) Even though it's a dependency ensure that slevomat is installed

composer require slevomat/coding-standard:^7.0

2) Update the config sets loaded

phpcs --config-set installed_paths /var/www/vendor/drupal/coder/coder_sniffer,/var/www/vendor/slevomat/coding-standard

3) code sniff & profit

phpcs --standard=Drupal --extensions='inc,php,module' --error-severity=1 --warning-severity=8 web/modules/custom -s

yas’s picture

@aczietlow

Thank you for summarizing the points. It helped and worked for me resolving the same error. Thanks!

JeremyFrench’s picture

The explanation here makes sense, but I wonder if it should have been classed as a breaking change and therefor a major update.

This issue was flagged for me when dependabot tried to do an upgrade of coder. I'm not sure if I would expect a minor upgrade to require a change to the build script.

It's too late now, but perhaps worth considering in future.

dpi’s picture

I found removing an extra <config name="installed_paths" in my phpcs.xml resolved the issue.

dealerdirect/phpcodesniffer-composer-installer was already included in the project, and added to the allow-plugins entry.

hitesh.koli’s picture

Adding the correct `installed_paths ` from #15 worked for me.

marciaibanez’s picture

Assigned: Unassigned » marciaibanez
marciaibanez’s picture

Assigned: marciaibanez » Unassigned

Status: Fixed » Closed (fixed)

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