Skip to content
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

✨ Restore SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation (#53) #74

Merged
merged 1 commit into from
Oct 20, 2023
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
1 change: 0 additions & 1 deletion PreviousNextDrupal/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 13 additions & 0 deletions tests/Sniffs/ReturnTypeHintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand All @@ -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';
}
Expand Down
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;
}