Skip to content

Commit

Permalink
Detect useless parameter annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
asispts committed Nov 3, 2023
1 parent 18d60a4 commit 30862f1
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions ptscs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
<!-- Useless typehint -->
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation" />
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation" />
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation" />


<!--++++++++++++++++++++++++++++++++++++
Expand Down
25 changes: 25 additions & 0 deletions tests/Sniffs/Slevomat/TypeHints/ParameterTypeHintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace Ptscs\Tests\Sniffs\Slevomat\TypeHints;

use Iterator;
use Ptscs\Tests\SniffTestCase;
use Ptscs\Tests\Utils\ErrorData;

final class ParameterTypeHintTest extends SniffTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch');
}

public static function provideTestData(): Iterator
{
yield [
[
new ErrorData(8, 'SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation'),
],
];
}
}
5 changes: 4 additions & 1 deletion tests/Sniffs/Slevomat/TypeHints/UselessDocblockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ protected function setUp(): void
public static function provideTestData(): Iterator
{
yield [
[ new ErrorData(22, 'SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation')],
[
new ErrorData(14, 'SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation'),
new ErrorData(22, 'SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation'),
],
];
}
}
12 changes: 12 additions & 0 deletions tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
/**
*/
public function check(string $useless, array $list, $missing): void
{
}
}
13 changes: 13 additions & 0 deletions tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace App;

final class Foobar
{
/**
* @param string $useless
*/
public function check(string $useless, array $list, $missing): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class Foobar

/**
* Class constructor.
* @param string $value
*/
public function __construct(string $value)
{
Expand Down

0 comments on commit 30862f1

Please sign in to comment.