diff --git a/tests/fixed/UselessConditions.php b/tests/fixed/UselessConditions.php index 95e2012a..cceb555e 100644 --- a/tests/fixed/UselessConditions.php +++ b/tests/fixed/UselessConditions.php @@ -19,6 +19,11 @@ public function uselessIfCondition(): bool return $bar === 'bar'; } + public function uselessIfConditionWithComment(): bool + { + return $bar === 'bar'; + } + public function uselessNegativeCondition(): bool { return $foo === 'foo'; diff --git a/tests/fixed/array_indentation.php b/tests/fixed/array_indentation.php index 626a7c37..d3f62c3b 100644 --- a/tests/fixed/array_indentation.php +++ b/tests/fixed/array_indentation.php @@ -3,7 +3,7 @@ declare(strict_types=1); $array = [ - 0, + 0, // this is the first index 1, 2, 3, diff --git a/tests/fixed/doc-comment-spacing.php b/tests/fixed/doc-comment-spacing.php index ad1dee4a..b115eded 100644 --- a/tests/fixed/doc-comment-spacing.php +++ b/tests/fixed/doc-comment-spacing.php @@ -46,7 +46,8 @@ public function c(iterable $foo): void * @deprecated * * @link https://example.com - * @see other + * @see Something else and make this see annotation + * multiline * @uses other * * @ORM\Id @@ -67,4 +68,38 @@ public function c(iterable $foo): void public function d(iterable $foo, iterable $bar): iterable { } + + /** + * Description + * More Description + * + * @internal + * @deprecated + * + * @link https://example.com + * @see other + * @uses other + * + * @ORM\Id + * @ORM\Column + * @ODM\Id + * @ODM\Column + * @PHPCR\Uuid + * @PHPCR\Field + * + * @param int[] $foo + * @param int[] $bar + * + * @return int[] + * + * @throws FooException + * @throws BarException + * + * @phpstan-param string $foo + * @psalm-param string $foo + * @phpstan-return true + */ + public function f(iterable $foo, iterable $bar): iterable + { + } } diff --git a/tests/fixed/forbidden-functions.php b/tests/fixed/forbidden-functions.php index f951ca36..c92daf3f 100644 --- a/tests/fixed/forbidden-functions.php +++ b/tests/fixed/forbidden-functions.php @@ -4,6 +4,7 @@ namespace Test; +use function array_map; use function chop; use function compact; use function extract; @@ -28,3 +29,5 @@ extract($bar); compact('foo', 'bar'); + +array_map('is_null', ['1', '2', null]); // forbidden function will not be detected diff --git a/tests/fixed/optimized-functions.php b/tests/fixed/optimized-functions.php index 0e69dbc5..c3d0174b 100644 --- a/tests/fixed/optimized-functions.php +++ b/tests/fixed/optimized-functions.php @@ -4,3 +4,4 @@ $args = [123, [123], true]; in_array(...$args); +in_array(...$args); diff --git a/tests/fixed/semicolon_spacing.php b/tests/fixed/semicolon_spacing.php index fa6c43ab..31f1dacb 100644 --- a/tests/fixed/semicolon_spacing.php +++ b/tests/fixed/semicolon_spacing.php @@ -9,3 +9,6 @@ $qb->select() ->from() ->where(); + +$qb->select() + ->from('mytable'); // we select from my table diff --git a/tests/fixed/superfluous-naming.php b/tests/fixed/superfluous-naming.php index cab66237..0105b602 100644 --- a/tests/fixed/superfluous-naming.php +++ b/tests/fixed/superfluous-naming.php @@ -12,6 +12,10 @@ class FooException extends RuntimeException { } +class FooError extends Error +{ +} + interface FooInterface { } diff --git a/tests/fixed/trailing_comma_on_array.php b/tests/fixed/trailing_comma_on_array.php index b2eba5b8..5f258930 100644 --- a/tests/fixed/trailing_comma_on_array.php +++ b/tests/fixed/trailing_comma_on_array.php @@ -6,3 +6,8 @@ 'key1' => 'value', 'key2' => 'value', ]; + +$arrayWithComment = [ + 'key1' => 'value', + 'key2' => 'value', // comment +]; diff --git a/tests/fixed/useless-semicolon.php b/tests/fixed/useless-semicolon.php index 358277bd..710682c6 100644 --- a/tests/fixed/useless-semicolon.php +++ b/tests/fixed/useless-semicolon.php @@ -13,3 +13,17 @@ for (;;) { echo 'To infity and beyond'; } + +for ( + $i = 0; $i < 10; + $i++ +); +{ + echo 'This will not be executed inside the for-loop'; +} + +{ + $var = 'This is useless'; +}; + +$myvar = 3; diff --git a/tests/input/UselessConditions.php b/tests/input/UselessConditions.php index bcb94341..564e23f7 100644 --- a/tests/input/UselessConditions.php +++ b/tests/input/UselessConditions.php @@ -27,6 +27,17 @@ public function uselessIfCondition(): bool return false; } + public function uselessIfConditionWithComment(): bool + { + if ($bar === 'bar') { + // Return true here in case $bar is bar + return true; + } + + // Return true here in case $bar is bar + return false; + } + public function uselessNegativeCondition(): bool { if ($foo !== 'foo') { diff --git a/tests/input/array_indentation.php b/tests/input/array_indentation.php index fa6e10ab..df373b32 100644 --- a/tests/input/array_indentation.php +++ b/tests/input/array_indentation.php @@ -3,7 +3,7 @@ declare(strict_types=1); $array = [ -0, +0, // this is the first index 1, 2, 3, diff --git a/tests/input/doc-comment-spacing.php b/tests/input/doc-comment-spacing.php index 7b1df121..24f1c3b8 100644 --- a/tests/input/doc-comment-spacing.php +++ b/tests/input/doc-comment-spacing.php @@ -57,10 +57,40 @@ public function c(iterable $foo): void * @PHPCR\Field * @ODM\Column * @ORM\Column - * @see other + * @see Something else and make this see annotation + * multiline * */ public function d(iterable $foo, iterable $bar): iterable { } + + /** + * + * Description + * More Description + * @phpstan-param string $foo + * @psalm-param string $foo + * @phpstan-return true + * @throws FooException + * @param int[] $foo + * @uses other + * @throws BarException + * @return int[] + * @ORM\Id + * @internal + * @link https://example.com + * @ODM\Id + * @deprecated + * @PHPCR\Uuid + * @param int[] $bar + * @PHPCR\Field + * @ODM\Column + * @ORM\Column + * @see other + * + */ + public function f(iterable $foo, iterable $bar): iterable + { + } } diff --git a/tests/input/example-class.php b/tests/input/example-class.php index 8e48cbb8..e6728ab0 100644 --- a/tests/input/example-class.php +++ b/tests/input/example-class.php @@ -23,6 +23,7 @@ class Example implements \IteratorAggregate { private const VERSION = \PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION; + /** @var null|int */ private $foo; diff --git a/tests/input/forbidden-functions.php b/tests/input/forbidden-functions.php index f951ca36..5c06a377 100644 --- a/tests/input/forbidden-functions.php +++ b/tests/input/forbidden-functions.php @@ -28,3 +28,5 @@ extract($bar); compact('foo', 'bar'); + +array_map('is_null', ['1', '2', null]); // forbidden function will not be detected diff --git a/tests/input/optimized-functions.php b/tests/input/optimized-functions.php index 0e69dbc5..2b0ab10a 100644 --- a/tests/input/optimized-functions.php +++ b/tests/input/optimized-functions.php @@ -4,3 +4,4 @@ $args = [123, [123], true]; in_array(...$args); +\in_array(...$args); diff --git a/tests/input/semicolon_spacing.php b/tests/input/semicolon_spacing.php index 169f8006..712351c6 100644 --- a/tests/input/semicolon_spacing.php +++ b/tests/input/semicolon_spacing.php @@ -11,3 +11,7 @@ ->from() ->where() ; + +$qb->select() + ->from('mytable') // we select from my table +; \ No newline at end of file diff --git a/tests/input/superfluous-naming.php b/tests/input/superfluous-naming.php index cab66237..0105b602 100644 --- a/tests/input/superfluous-naming.php +++ b/tests/input/superfluous-naming.php @@ -12,6 +12,10 @@ class FooException extends RuntimeException { } +class FooError extends Error +{ +} + interface FooInterface { } diff --git a/tests/input/trailing_comma_on_array.php b/tests/input/trailing_comma_on_array.php index 3b39e357..431e2551 100644 --- a/tests/input/trailing_comma_on_array.php +++ b/tests/input/trailing_comma_on_array.php @@ -6,3 +6,8 @@ 'key1' => 'value', 'key2' => 'value' ]; + +$arrayWithComment = [ + 'key1' => 'value', + 'key2' => 'value' // comment +]; diff --git a/tests/input/useless-semicolon.php b/tests/input/useless-semicolon.php index 66149f36..0a681916 100644 --- a/tests/input/useless-semicolon.php +++ b/tests/input/useless-semicolon.php @@ -7,9 +7,20 @@ }; do { - echo 1; + ;echo 1; } while (! false); for (;;) { echo 'To infity and beyond'; }; + +for ($i = 0 ; $i < 10; $i++); +{ + echo 'This will not be executed inside the for-loop'; +} + +{ + $var = 'This is useless'; +}; + +$myvar = 3;;