Skip to content

Ignoring multiple rules using phpcs:ignore only ignores the first one since version 4.0.0 #1277

Closed

Description

@Domi04151309

Describe the bug

Ignoring multiple rules using phpcs:ignore only ignores the first one since version 4.0.0

Code sample

<?php

  final class CustomSessionHandler extends SessionHandler {
    // phpcs:ignore Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps, PSR1.Methods.CamelCapsMethodName.NotCamelCaps
    public function create_sid(): string {
      return 'example';
    }
  }
?>

Custom ruleset

<?xml version="1.0"?>
<ruleset name="Custom Standard" namespace="CS\Standard">
	<description>A custom coding standard</description>

	<arg name="tab-width" value="2" />

	<rule ref="Generic">
		<exclude name="Generic.Arrays.ArrayIndent.KeyIncorrect" />
		<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found" />
		<exclude name="Generic.Commenting" />
		<exclude name="Generic.ControlStructures.InlineControlStructure.NotAllowed" />
		<exclude name="Generic.Files.EndFileNoNewline.Found" />
		<exclude name="Generic.Files.InlineHTML.Found" />
		<exclude name="Generic.Files.LineLength" />
		<exclude name="Generic.Files.LowercasedFilename.NotFound" />
		<exclude name="Generic.Formatting" />
		<exclude name="Generic.Functions.OpeningFunctionBraceBsdAllman.BraceOnSameLine" />
		<exclude name="Generic.Metrics.CyclomaticComplexity" />
		<exclude name="Generic.PHP.RequireStrictTypes.MissingDeclaration" />
		<exclude name="Generic.PHP.UpperCaseConstant.Found" />
		<exclude name="Generic.Strings.UnnecessaryStringConcat.Found" />
		<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing.SpaceAfterOpen" />
		<exclude name="Generic.WhiteSpace.ArbitraryParenthesesSpacing.SpaceBeforeClose" />
		<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
		<exclude name="Generic.WhiteSpace.ScopeIndent.Incorrect" />
		<exclude name="Generic.WhiteSpace.ScopeIndent.IncorrectExact" />
	</rule>

	<rule ref="PSR12">
		<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
		<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
		<exclude name="PSR12.ControlStructures.ControlStructureSpacing.LineIndent" />
		<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceAfter" />
		<exclude name="PSR12.Operators.OperatorSpacing.NoSpaceBefore" />
		<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
		<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed" />
		<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakIndent" />
		<exclude name="PSR2.Files.ClosingTag.NotAllowed" />
		<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
		<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
		<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.Indent" />
	</rule>
</ruleset>

To reproduce

Steps to reproduce the behavior:

  1. Create a file with the code sample above
  2. Run phpcs with the given ruleset
  3. See the error message for a rule that should be ignored
----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------------------------------------
 5 | ERROR | Method name "CustomSessionHandler::create_sid" is not in camel caps format (PSR1.Methods.CamelCapsMethodName.NotCamelCaps)
----------------------------------------------------------------------------------------------------------------------------------------

Expected behavior

As was the case in 3.x.x both rules should be ignored.

Versions

Operating System Linux 6.8.0-83-generic
PHP version 8.3.6
PHP_CodeSniffer version 4.0.0
Standard custom
Install type Composer (local)

Additional context

No additional context.

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the 4.x branch of PHP_CodeSniffer.

Activity

  1. jrfnl commented on Sep 20, 2025

    @jrfnl
    Member

    @Domi04151309 Thanks for reporting this. I can reproduce the issue with the provided information (working on PHPCS 3.x, not working on 4.x).

    Having said that, I'm not sure whether this should really be regarded as a bug in PHPCS as the syntax you are using in the phpcs:ignore is not a syntax which was ever officially supported.

    phpcs:ignore (and disable/enable) take a comma-separate list of codes to ignore. not a "comma space" separated list.

    So, changing the ignore statement to use valid syntax fixes the issue immediately (tested and confirmed):

    // phpcs:ignore Generic.NamingConventions.CamelCapsFunctionName.ScopeNotCamelCaps,PSR1.Methods.CamelCapsMethodName.NotCamelCaps
    
  2. Domi04151309 commented on Sep 20, 2025

    @Domi04151309
    Author

    Thanks for the quick reply. Removing the space works for me but maybe this can be added to the release notes as an additional info in case other people accidentally used this unofficial syntax.

  3. jrfnl commented on Sep 20, 2025

    @jrfnl
    Member

    maybe this can be added to the release notes as an additional info in case other people accidentally used this unofficial syntax.

    I'm first going to quickly look into how easy it would be to bring this whitespace tolerance back. If the fix would be straight forward, expect a PR. If it would turn out to be complicated to fix, I'll add something to the upgrade guides.

    For now, bear with me.

    For the record: I believe this was broken in #123

  4. added this to the 4.0.1 milestone on Sep 21, 2025
  5. self-assigned this
    on Sep 21, 2025
  6. jrfnl commented on Sep 21, 2025

    @jrfnl
    Member

    @Domi04151309 If you have a chance, could you test PR #1278 ?

  7. jrfnl commented on Nov 10, 2025

    @jrfnl
    Member

    @Domi04151309 Sorry it took a while, but the fix for this has now been released in the PHPCS 4.0.1 release,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions