Skip to content

Commit

Permalink
fix: Minor static analysis fixes.
Browse files Browse the repository at this point in the history
Since PHPStan 1.5.7, some ignored errors are gone, which is a good thing.
  • Loading branch information
drupol committed Apr 22, 2022
1 parent 27f2fe2 commit 2ce3510
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"loophp/iterators": "^1.6"
},
"require-dev": {
"ext-xdebug": "*",
"amphp/parallel-functions": "^1",
"doctrine/collections": "^1.6",
"drupol/php-conventions": "^5",
Expand Down
9 changes: 4 additions & 5 deletions tests/static-analysis/append.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@ function append_checkMixed(CollectionInterface $collection): void

// These should work but they don't due to the way analysers interpret empty()
// or variadic parameters of different types passed to append()
/** @psalm-suppress InvalidArgument @phpstan-ignore-next-line */
/** @psalm-suppress InvalidArgument */
append_checkMixed(Collection::empty()->append(1, '2'));
/** @psalm-suppress InvalidArgument */
append_checkMixed(Collection::empty()->append(...[1, '2']));
/** @phpstan-ignore-next-line */
append_checkMixed(Collection::fromIterable(['foo' => 1, 'bar' => '2'])->append(1, '3'));

// ## VALID FAILURE ###
append_checkList(Collection::empty()->append(1, 'foo')); // @phpstan-ignore-line
append_checkList(Collection::empty()->append(1, 'foo'));
append_checkList(Collection::fromIterable([5])->append('foo')); // @phpstan-ignore-line
append_checkList(Collection::fromIterable([5])->append('foo', 1)); // @phpstan-ignore-line

/** @psalm-suppress InvalidScalarArgument @phpstan-ignore-next-line */
/** @psalm-suppress InvalidScalarArgument */
append_checkListWithMap(Collection::empty()->append($foo, ['bar' => 'baz']));
/** @psalm-suppress InvalidScalarArgument @phpstan-ignore-next-line */
append_checkListWithMap(Collection::fromIterable([1 => $foo])->append(['bar' => 'baz']));
Expand All @@ -89,7 +88,7 @@ function append_checkMixed(CollectionInterface $collection): void
*/
append_checkMap(Collection::fromIterable($foo)->append(3));

/** @psalm-suppress InvalidArgument @phpstan-ignore-next-line */
/** @psalm-suppress InvalidArgument */
append_checkMixed(Collection::empty()->append(1, [3]));
/** @psalm-suppress InvalidArgument */
append_checkMixed(Collection::empty()->append(...[1, [3]]));
Expand Down
1 change: 0 additions & 1 deletion tests/static-analysis/zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ static function (): Generator {

// With two parameters of different types
// Fails with PHPStan, not in PSalm.
/** @phpstan-ignore-next-line */
zip_checkBoolStringInt(Collection::fromIterable($generator())->zip(range('a', 'c'), range(1, 3)));

0 comments on commit 2ce3510

Please sign in to comment.