-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove useless property, parameter, and return annotations (#16)
* Detect useless property annotation * Detect useless return annotation * Detect useless parameter annotation
- Loading branch information
Showing
14 changed files
with
326 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 PropertyTypeHintTest extends SniffTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch'); | ||
} | ||
|
||
public static function provideTestData(): Iterator | ||
{ | ||
yield [ | ||
[ | ||
new ErrorData(10, 'SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation'), | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Ptscs\Tests\Sniffs\Slevomat\TypeHints; | ||
|
||
use Iterator; | ||
use Ptscs\Tests\SniffTestCase; | ||
use Ptscs\Tests\Utils\ErrorData; | ||
|
||
final class ReturnTypeHintTest 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.ReturnTypeHint.UselessAnnotation')], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Ptscs\Tests\Sniffs\Slevomat\TypeHints; | ||
|
||
use Iterator; | ||
use Ptscs\Tests\SniffTestCase; | ||
use Ptscs\Tests\Utils\ErrorData; | ||
|
||
final class UselessDocblockTest extends SniffTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->appendExclude('Squiz.Classes.ClassFileName.NoMatch'); | ||
} | ||
|
||
public static function provideTestData(): Iterator | ||
{ | ||
yield [ | ||
[ | ||
new ErrorData(14, 'SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation'), | ||
new ErrorData(22, 'SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation'), | ||
], | ||
]; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
tests/Sniffs/Slevomat/TypeHints/_data/ParameterTypeHint.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/Sniffs/Slevomat/TypeHints/_data/PropertyTypeHint.php.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
final class Foobar | ||
{ | ||
private string $useless; | ||
|
||
/** | ||
* @Assert\NotBlank | ||
*/ | ||
private $missing; | ||
|
||
/** | ||
* Description | ||
* | ||
*/ | ||
private string $value1; | ||
|
||
private ?int $value2 = null; | ||
|
||
private string|int|float $value3; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private array $value4; | ||
|
||
/** | ||
* @var string The hashed password | ||
*/ | ||
private string $password; | ||
|
||
private $inferMissing; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $inferUseless; | ||
|
||
public function __construct(string $inferMissing, int $inferUseless) | ||
{ | ||
$this->inferMissing = $inferMissing; | ||
$this->inferUseless = $inferUseless; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/Sniffs/Slevomat/TypeHints/_data/PropertyTypeHint.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
final class Foobar | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private string $useless; | ||
|
||
/** | ||
* @Assert\NotBlank | ||
*/ | ||
private $missing; | ||
|
||
/** | ||
* Description | ||
* | ||
*/ | ||
private string $value1; | ||
|
||
private ?int $value2 = null; | ||
|
||
private string|int|float $value3; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private array $value4; | ||
|
||
/** | ||
* @var string The hashed password | ||
*/ | ||
private string $password; | ||
|
||
private $inferMissing; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $inferUseless; | ||
|
||
public function __construct(string $inferMissing, int $inferUseless) | ||
{ | ||
$this->inferMissing = $inferMissing; | ||
$this->inferUseless = $inferUseless; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/Sniffs/Slevomat/TypeHints/_data/ReturnTypeHint.php.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
final class Foobar | ||
{ | ||
/** | ||
*/ | ||
public function useless(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function missing() | ||
{ | ||
return 'missing'; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/Sniffs/Slevomat/TypeHints/_data/ReturnTypeHint.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
final class Foobar | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function useless(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function missing() | ||
{ | ||
return 'missing'; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/Sniffs/Slevomat/TypeHints/_data/UselessDocblock.php.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
final class Foobar | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* Class constructor. | ||
*/ | ||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
*/ | ||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/Sniffs/Slevomat/TypeHints/_data/UselessDocblock.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App; | ||
|
||
final class Foobar | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* Class constructor. | ||
* @param string $value | ||
*/ | ||
public function __construct(string $value) | ||
{ | ||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue(): string | ||
{ | ||
return $this->value; | ||
} | ||
} |