Skip to content

Ruleset: remove support for sniffs nor implementing Sniff interface #986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions src/Ruleset.php
Original file line number Diff line number Diff line change
Expand Up @@ -1418,24 +1418,9 @@ public function registerSniffs($files, $restrictions, $exclusions)
$message = 'All sniffs must implement the PHP_CodeSniffer\\Sniffs\\Sniff interface.'.PHP_EOL;
$message .= "Interface not implemented for sniff $className.".PHP_EOL;
$message .= 'Contact the sniff author to fix the sniff.';
$this->msgCache->add($message, MessageCollector::DEPRECATED);

// Skip classes which don't implement the register() or process() methods.
if (method_exists($className, 'register') === false
|| method_exists($className, 'process') === false
) {
$errorMsg = 'Sniff class %s is missing required method %s().';
if (method_exists($className, 'register') === false) {
$this->msgCache->add(sprintf($errorMsg, $className, 'register'), MessageCollector::ERROR);
}

if (method_exists($className, 'process') === false) {
$this->msgCache->add(sprintf($errorMsg, $className, 'process'), MessageCollector::ERROR);
}

continue;
}
}//end if
$this->msgCache->add($message, MessageCollector::ERROR);
continue;
}

$listeners[$className] = $className;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<rule ref="TestStandard">
<exclude name="TestStandard.SupportedTokenizers"/>
<exclude name="TestStandard.InvalidSniffs"/>
<exclude name="TestStandard.InvalidSniffError"/>
<exclude name="TestStandard.MissingInterface.InvalidImplementsWithoutImplement"/>
</rule>

Expand Down
18 changes: 9 additions & 9 deletions tests/Core/Ruleset/RegisterSniffsMissingInterfaceTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface.
* Tests removed support for sniffs not implementing the PHPCS `Sniff` interface.
*
* @author Juliette Reinders Folmer <[email protected]>
* @copyright 2025 PHPCSStandards and contributors
Expand All @@ -11,14 +11,14 @@

use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHPUnit\Framework\TestCase;
use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;

/**
* Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface.
* Tests removed support for sniffs not implementing the PHPCS `Sniff` interface.
*
* @covers \PHP_CodeSniffer\Ruleset::registerSniffs
*/
final class RegisterSniffsMissingInterfaceTest extends TestCase
final class RegisterSniffsMissingInterfaceTest extends AbstractRulesetTestCase
{


Expand All @@ -41,25 +41,25 @@ public function testNoNoticesForSniffsImplementingInterface()


/**
* Test that a deprecation notice is shown if a sniff doesn't implement the Sniff interface.
* Test that an error is shown if a sniff doesn't implement the Sniff interface.
*
* @return void
*/
public function testDeprecationNoticeWhenSniffDoesntImplementInterface()
public function testErrorWhenSniffDoesntImplementInterface()
{
// Set up the ruleset.
$standard = __DIR__.'/RegisterSniffsMissingInterfaceInvalidTest.xml';
$config = new ConfigDouble(["--standard=$standard"]);

$expected = 'DEPRECATED: All sniffs must implement the PHP_CodeSniffer\\Sniffs\\Sniff interface.'.PHP_EOL;
$expected = 'ERROR: All sniffs must implement the PHP_CodeSniffer\\Sniffs\\Sniff interface.'.PHP_EOL;
$expected .= 'Interface not implemented for sniff Fixtures\\TestStandard\\Sniffs\\MissingInterface\\InvalidImplementsWithoutImplementSniff.'.PHP_EOL;
$expected .= 'Contact the sniff author to fix the sniff.'.PHP_EOL.PHP_EOL;

$this->expectOutputString($expected);
$this->expectRuntimeExceptionMessage($expected);

new Ruleset($config);

}//end testDeprecationNoticeWhenSniffDoesntImplementInterface()
}//end testErrorWhenSniffDoesntImplementInterface()


}//end class

This file was deleted.

This file was deleted.

This file was deleted.

80 changes: 0 additions & 80 deletions tests/Core/Ruleset/RegisterSniffsRejectsInvalidSniffTest.php

This file was deleted.

1 change: 0 additions & 1 deletion tests/Core/Ruleset/ShowSniffDeprecationsTest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<exclude name="TestStandard.DeprecatedInvalid"/>
<exclude name="TestStandard.SupportedTokenizers"/>
<exclude name="TestStandard.InvalidSniffs"/>
<exclude name="TestStandard.InvalidSniffError"/>
<exclude name="TestStandard.MissingInterface"/>
</rule>

Expand Down