Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Restore `SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnn…
Browse files Browse the repository at this point in the history
…otation` (#53)

This reverts commit a4d68e3.
dpi committed Oct 20, 2023
1 parent 6003f7a commit b005e25
Showing 6 changed files with 39 additions and 6 deletions.
1 change: 0 additions & 1 deletion PreviousNextDrupal/ruleset.xml
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing" />
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation"><severity>0</severity></rule>

<!-- Squiz.PHP -->
<rule ref="Squiz.PHP.NonExecutableCode.Unreachable"><severity>0</severity></rule>
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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._
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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": {
13 changes: 13 additions & 0 deletions tests/Sniffs/ReturnTypeHintTest.php
Original file line number Diff line number Diff line change
@@ -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';
}
12 changes: 12 additions & 0 deletions tests/Sniffs/fixtures/ReturnTypeHintUseless.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types = 1);

/**
* A function.
*
* @return int|null
*/
function foo(): ?int {
return 1;
}
13 changes: 13 additions & 0 deletions tests/Sniffs/fixtures/ReturnTypeHintUselessWithDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types = 1);

/**
* A function.
*
* @return int|null
* Returns an int or NULL if this or that.
*/
function foo(): ?int {
return 1;
}

0 comments on commit b005e25

Please sign in to comment.