diff --git a/composer.json b/composer.json index da9abf911..d66660e85 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "infection/infection": "^0.23.0 || ^0.24.0", "infection/phpspec-adapter": "^0.1.2", "phpspec/phpspec": "^7.1", - "phpstan/phpstan-strict-rules": "^0.12", + "phpstan/phpstan-strict-rules": "^1.0", "psr/cache": "^1.0", "symfony/cache": "^5" }, diff --git a/grumphp.yml b/grumphp.yml index 274e15800..cd69ce6f2 100644 --- a/grumphp.yml +++ b/grumphp.yml @@ -24,6 +24,7 @@ parameters: - "/vendor/" # PHPStan + tasks.phpstan.level: 8 tasks.phpstan.blocking: true tasks.phpstan.ignore_patterns: - "/.github/" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3ea8e31d4..6cea0f29f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,32 +1,292 @@ parameters: ignoreErrors: + - + message: "#^Method loophp\\\\collection\\\\Collection\\:\\:empty\\(\\) should return loophp\\\\collection\\\\Collection\\ but returns loophp\\\\collection\\\\Collection\\<\\(int&NewTKey\\)\\|\\(NewTKey&string\\), NewT\\>\\.$#" + count: 1 + path: src/Collection.php + + - + message: "#^Template type NewT of method loophp\\\\collection\\\\Collection\\:\\:empty\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Collection.php + + - + message: "#^Template type NewTKey of method loophp\\\\collection\\\\Collection\\:\\:empty\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Collection.php + + - + message: "#^PHPDoc tag @param for parameter \\$comparatorCallback contains unresolvable type\\.$#" + count: 1 + path: src/Contract/Operation/Duplicateable.php + + - + message: "#^Template type T of method loophp\\\\collection\\\\Contract\\\\Operation\\\\Rangeable\\:\\:range\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Contract/Operation/Rangeable.php + + - + message: "#^Template type TKey of method loophp\\\\collection\\\\Contract\\\\Operation\\\\Rangeable\\:\\:range\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Contract/Operation/Rangeable.php + + - + message: "#^PHPDoc tag @param for parameter \\$comparatorCallback contains unresolvable type\\.$#" + count: 1 + path: src/Contract/Operation/Sameable.php + + - + message: "#^Template type TKey of method loophp\\\\collection\\\\Contract\\\\Operation\\\\Unfoldable\\:\\:unfold\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Contract/Operation/Unfoldable.php + + - + message: "#^Anonymous function should return string but returns class\\-string\\|false\\.$#" + count: 1 + path: src/Iterator/TypedIterator.php + + - + message: "#^Property loophp\\\\collection\\\\Iterator\\\\ProxyIterator\\\\:\\:\\$iterator \\(Iterator\\\\) does not accept loophp\\\\collection\\\\Iterator\\\\ClosureIterator\\\\.$#" + count: 1 + path: src/Iterator/TypedIterator.php + + - + message: "#^Template type NewT of method loophp\\\\collection\\\\Operation\\\\Associate\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Associate.php + + - + message: "#^Template type NewTKey of method loophp\\\\collection\\\\Operation\\\\Associate\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Associate.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\AsyncMap\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/AsyncMap.php + - message: "#^Anonymous function with return type void returns void but should not return anything\\.$#" count: 2 path: src/Operation/Combinate.php - - message: "#^Method loophp\\\\collection\\\\Operation\\\\Group\\:\\:__invoke\\(\\) should return Closure\\(Iterator\\\\)\\: Generator\\, mixed, mixed\\> but returns Closure\\(Iterator\\)\\: Generator\\&nonEmpty, mixed, void\\>\\.$#" + message: "#^Template type U of method loophp\\\\collection\\\\Operation\\\\Combine\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Combine.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Current\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Current.php + + - + message: "#^Template type U of method loophp\\\\collection\\\\Operation\\\\Distinct\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Distinct.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/DropWhile.php + + - + message: "#^Template type U of method loophp\\\\collection\\\\Operation\\\\Duplicate\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Duplicate.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/Filter.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Find\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Find.php + + - + message: "#^Template type IKey of method loophp\\\\collection\\\\Operation\\\\FlatMap\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/FlatMap.php + + - + message: "#^Template type IValue of method loophp\\\\collection\\\\Operation\\\\FlatMap\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/FlatMap.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Get\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Get.php + + - + message: "#^Method loophp\\\\collection\\\\Operation\\\\Group\\:\\:__invoke\\(\\) should return Closure\\(Iterator\\\\)\\: Generator\\, mixed, mixed\\> but returns Closure\\(Iterator\\)\\: Generator\\, mixed, void\\>\\.$#" count: 1 path: src/Operation/Group.php - - message: "#^Strict comparison using \\=\\=\\= between array\\(\\) and array\\&nonEmpty will always evaluate to false\\.$#" + message: "#^Template type NewTKey of method loophp\\\\collection\\\\Operation\\\\GroupBy\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" count: 1 - path: src/Operation/Permutate.php + path: src/Operation/GroupBy.php - - message: "#^Anonymous function should return EmptyIterator but return statement is missing\\.$#" + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Map\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" count: 1 - path: src/Operation/Times.php + path: src/Operation/Map.php - - message: "#^Anonymous function should have native return typehint \"\\?T\"\\.$#" + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 2 + path: src/Operation/MatchOne.php + + - + message: "#^PHPDoc tag @var for constant loophp\\\\collection\\\\Operation\\\\Nullsy\\:\\:VALUES contains unresolvable type\\.$#" count: 1 - path: src/Operation/Unwindow.php + path: src/Operation/Nullsy.php + + - + message: "#^Template type U of method loophp\\\\collection\\\\Operation\\\\Product\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Product.php + + - + message: "#^Template type UKey of method loophp\\\\collection\\\\Operation\\\\Product\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Product.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Reduce\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Reduce.php + + - + message: "#^Template type W of method loophp\\\\collection\\\\Operation\\\\Reduce\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Reduce.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\Reduction\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Reduction.php + + - + message: "#^Template type W of method loophp\\\\collection\\\\Operation\\\\Reduction\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Reduction.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/Reject.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\ScanLeft\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanLeft.php + + - + message: "#^Template type W of method loophp\\\\collection\\\\Operation\\\\ScanLeft\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanLeft.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\ScanLeft1\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanLeft1.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\ScanRight\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanRight.php + + - + message: "#^Template type W of method loophp\\\\collection\\\\Operation\\\\ScanRight\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanRight.php + + - + message: "#^Template type V of method loophp\\\\collection\\\\Operation\\\\ScanRight1\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/ScanRight1.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/Since.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/Split.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/TakeWhile.php + + - + message: "#^While loop condition is always true\\.$#" + count: 1 + path: src/Operation/Unfold.php + + - + message: "#^Parameter \\#1 \\$ of closure expects array\\\\)\\: bool\\>, array\\ given\\.$#" + count: 1 + path: src/Operation/Until.php - message: "#^Foreach overwrites \\$value with its value variable\\.$#" count: 1 path: src/Operation/Unwindow.php + - + message: "#^Template type U of method loophp\\\\collection\\\\Operation\\\\Zip\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Zip.php + + - + message: "#^Template type UKey of method loophp\\\\collection\\\\Operation\\\\Zip\\:\\:__invoke\\(\\) is not referenced in a parameter\\.$#" + count: 1 + path: src/Operation/Zip.php + + - + message: "#^Parameter \\#1 \\$array of function all_checkList expects array\\, array\\ given\\.$#" + count: 1 + path: tests/static-analysis/all.php + + - + message: "#^Parameter \\#1 \\$array of function all_checkMap expects array\\, array\\ given\\.$#" + count: 1 + path: tests/static-analysis/all.php + + - + message: "#^Parameter \\#1 \\$array of function all_checkMixed expects array\\, array\\ given\\.$#" + count: 1 + path: tests/static-analysis/all.php + + - + message: "#^While loop condition is always true\\.$#" + count: 2 + path: tests/static-analysis/flip.php + + - + message: "#^While loop condition is always true\\.$#" + count: 4 + path: tests/static-analysis/random.php + + - + message: "#^While loop condition is always true\\.$#" + count: 4 + path: tests/static-analysis/shuffle.php + + - + message: "#^While loop condition is always true\\.$#" + count: 3 + path: tests/static-analysis/unpack.php + + - + message: "#^While loop condition is always true\\.$#" + count: 2 + path: tests/static-analysis/wrap.php + diff --git a/phpstan-unsupported-baseline.neon b/phpstan-unsupported-baseline.neon index 3311886b0..fa2c0b6cd 100644 --- a/phpstan-unsupported-baseline.neon +++ b/phpstan-unsupported-baseline.neon @@ -4,18 +4,3 @@ parameters: message: "#^Generic type loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable\\\\> in PHPDoc tag @extends does not specify all template types of interface loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable\\: TKey, T, NewTKey, NewT$#" count: 1 path: src/Contract/Collection.php - - - - message: "#^PHPDoc tag @template T for class loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable with bound type array\\ is not supported\\.$#" - count: 1 - path: src/Contract/Operation/Unpackable.php - - - - message: "#^PHPDoc tag @template T for interface loophp\\\\collection\\\\Contract\\\\Operation\\\\Unpackable with bound type array\\ is not supported\\.$#" - count: 1 - path: src/Contract/Operation/Unpackable.php - - - - message: "#^PHPDoc tag @template T for class loophp\\\\collection\\\\Operation\\\\Unpack with bound type array\\ is not supported\\.$#" - count: 1 - path: src/Operation/Unpack.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 8e41f610f..4b686a078 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,5 @@ +parameters: + reportUnmatchedIgnoredErrors: false includes: - phpstan-baseline.neon - phpstan-unsupported-baseline.neon diff --git a/src/Contract/Operation/Timesable.php b/src/Contract/Operation/Timesable.php index b625a95f0..6f4c17eed 100644 --- a/src/Contract/Operation/Timesable.php +++ b/src/Contract/Operation/Timesable.php @@ -16,8 +16,6 @@ interface Timesable /** * Create a new instance by invoking the callback a given amount of times. * - * @template TKey - * @template TKey * @template T * * @param null|callable(int): (int|T) $callback diff --git a/src/Operation/Times.php b/src/Operation/Times.php index 1cc2e3ae1..c52746a5e 100644 --- a/src/Operation/Times.php +++ b/src/Operation/Times.php @@ -10,7 +10,6 @@ namespace loophp\collection\Operation; use Closure; -use EmptyIterator; use Generator; use Iterator; @@ -47,7 +46,7 @@ public function __invoke(): Closure */ static function (?Iterator $iterator = null) use ($number, $callback): Generator { if (1 > $number) { - return new EmptyIterator(); + return; } $callback ??= static fn (int $value): int => $value;