Skip to content

Commit f267f46

Browse files
authored
Merge pull request #986 from PHPCSStandards/phpcs-4.0/feature/694-4-ruleset-dont-allow-sniffs-not-implementing-sniff-interface
Ruleset: remove support for sniffs nor implementing `Sniff` interface
2 parents 56abd67 + a611742 commit f267f46

11 files changed

+12
-181
lines changed

src/Ruleset.php

+3-18
Original file line numberDiff line numberDiff line change
@@ -1418,24 +1418,9 @@ public function registerSniffs($files, $restrictions, $exclusions)
14181418
$message = 'All sniffs must implement the PHP_CodeSniffer\\Sniffs\\Sniff interface.'.PHP_EOL;
14191419
$message .= "Interface not implemented for sniff $className.".PHP_EOL;
14201420
$message .= 'Contact the sniff author to fix the sniff.';
1421-
$this->msgCache->add($message, MessageCollector::DEPRECATED);
1422-
1423-
// Skip classes which don't implement the register() or process() methods.
1424-
if (method_exists($className, 'register') === false
1425-
|| method_exists($className, 'process') === false
1426-
) {
1427-
$errorMsg = 'Sniff class %s is missing required method %s().';
1428-
if (method_exists($className, 'register') === false) {
1429-
$this->msgCache->add(sprintf($errorMsg, $className, 'register'), MessageCollector::ERROR);
1430-
}
1431-
1432-
if (method_exists($className, 'process') === false) {
1433-
$this->msgCache->add(sprintf($errorMsg, $className, 'process'), MessageCollector::ERROR);
1434-
}
1435-
1436-
continue;
1437-
}
1438-
}//end if
1421+
$this->msgCache->add($message, MessageCollector::ERROR);
1422+
continue;
1423+
}
14391424

14401425
$listeners[$className] = $className;
14411426

tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/InvalidSniffError/NoImplementsNoProcessSniff.php

-17
This file was deleted.

tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/InvalidSniffError/NoImplementsNoRegisterOrProcessSniff.php

-12
This file was deleted.

tests/Core/Ruleset/Fixtures/TestStandard/Sniffs/InvalidSniffError/NoImplementsNoRegisterSniff.php

-19
This file was deleted.

tests/Core/Ruleset/ProcessRulesetAutoExpandSniffsDirectoryTest.xml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<rule ref="TestStandard">
77
<exclude name="TestStandard.SupportedTokenizers"/>
88
<exclude name="TestStandard.InvalidSniffs"/>
9-
<exclude name="TestStandard.InvalidSniffError"/>
109
<exclude name="TestStandard.MissingInterface.InvalidImplementsWithoutImplement"/>
1110
</rule>
1211

tests/Core/Ruleset/RegisterSniffsMissingInterfaceTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface.
3+
* Tests removed support for sniffs not implementing the PHPCS `Sniff` interface.
44
*
55
* @author Juliette Reinders Folmer <[email protected]>
66
* @copyright 2025 PHPCSStandards and contributors
@@ -11,14 +11,14 @@
1111

1212
use PHP_CodeSniffer\Ruleset;
1313
use PHP_CodeSniffer\Tests\ConfigDouble;
14-
use PHPUnit\Framework\TestCase;
14+
use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;
1515

1616
/**
17-
* Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface.
17+
* Tests removed support for sniffs not implementing the PHPCS `Sniff` interface.
1818
*
1919
* @covers \PHP_CodeSniffer\Ruleset::registerSniffs
2020
*/
21-
final class RegisterSniffsMissingInterfaceTest extends TestCase
21+
final class RegisterSniffsMissingInterfaceTest extends AbstractRulesetTestCase
2222
{
2323

2424

@@ -41,25 +41,25 @@ public function testNoNoticesForSniffsImplementingInterface()
4141

4242

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

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

58-
$this->expectOutputString($expected);
58+
$this->expectRuntimeExceptionMessage($expected);
5959

6060
new Ruleset($config);
6161

62-
}//end testDeprecationNoticeWhenSniffDoesntImplementInterface()
62+
}//end testErrorWhenSniffDoesntImplementInterface()
6363

6464

6565
}//end class

tests/Core/Ruleset/RegisterSniffsRejectsInvalidSniffNoImplementsNoProcessTest.xml

-8
This file was deleted.

tests/Core/Ruleset/RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml

-8
This file was deleted.

tests/Core/Ruleset/RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterTest.xml

-8
This file was deleted.

tests/Core/Ruleset/RegisterSniffsRejectsInvalidSniffTest.php

-80
This file was deleted.

tests/Core/Ruleset/ShowSniffDeprecationsTest.xml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
<exclude name="TestStandard.DeprecatedInvalid"/>
88
<exclude name="TestStandard.SupportedTokenizers"/>
99
<exclude name="TestStandard.InvalidSniffs"/>
10-
<exclude name="TestStandard.InvalidSniffError"/>
1110
<exclude name="TestStandard.MissingInterface"/>
1211
</rule>
1312

0 commit comments

Comments
 (0)