diff --git a/PreviousNextDrupal/ruleset.xml b/PreviousNextDrupal/ruleset.xml index 351bfe4..09b1e7a 100644 --- a/PreviousNextDrupal/ruleset.xml +++ b/PreviousNextDrupal/ruleset.xml @@ -42,7 +42,6 @@ - 0 0 diff --git a/README.md b/README.md index 34ba6e4..dea2c81 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,6 @@ Developers are entrusted to properly self-describe code. Suggestions to improve This rule has trouble with newer PHP syntax, especially expression throwables. In any case this rule is best enforced with static analysis. -#### SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation - -This rule is too greedy about what it thinks is 'useless'. Unique detail is removed. - --- _Drupal is a registered trademark of Dries Buytaert._ diff --git a/composer.json b/composer.json index 8b996da..a69b778 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": "^8.0", "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", "drupal/coder": "^8.3.21", - "slevomat/coding-standard": "^8.7.1", + "slevomat/coding-standard": "^8.13.2", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { diff --git a/tests/Sniffs/ReturnTypeHintTest.php b/tests/Sniffs/ReturnTypeHintTest.php index 2932611..3656182 100644 --- a/tests/Sniffs/ReturnTypeHintTest.php +++ b/tests/Sniffs/ReturnTypeHintTest.php @@ -4,6 +4,8 @@ namespace PreviousNext\CodingStandard\Tests\Sniffs; +use SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff; + /** * @covers \SlevomatCodingStandard\Sniffs\TypeHints\ReturnTypeHintSniff * @see https://github.com/slevomat/coding-standard/blob/master/doc/type-hints.md#slevomatcodingstandardtypehintsreturntypehint- @@ -26,6 +28,17 @@ public function testIgnoreTraversable(): void { self::assertNoSniffError($report, 8); } + public function testUseless(): void { + $report = self::checkFile(__DIR__ . '/fixtures/ReturnTypeHintUseless.php'); + self::assertSniffError($report, 8, code: ReturnTypeHintSniff::CODE_USELESS_ANNOTATION); + } + + public function testUselessWithDescription(): void { + $report = self::checkFile(__DIR__ . '/fixtures/ReturnTypeHintUselessWithDescription.php'); + self::assertSame(0, $report->getErrorCount()); + self::assertNoSniffError($report, 8); + } + protected static function getSniffName(): string { return 'SlevomatCodingStandard.TypeHints.ReturnTypeHint'; } diff --git a/tests/Sniffs/fixtures/ReturnTypeHintUseless.php b/tests/Sniffs/fixtures/ReturnTypeHintUseless.php new file mode 100644 index 0000000..8f57d33 --- /dev/null +++ b/tests/Sniffs/fixtures/ReturnTypeHintUseless.php @@ -0,0 +1,12 @@ +