cs278
Repos
67
Followers
39
Following
20

Audit Composer dependencies for security vulnerabilities without using an external service.

5
2

Events

opened issue
`array_{shift,pop}()` return type inference wrong depending on size of array

Bug report

Reproduced 1.8.3 and then on 1.8.5.

When an array has a defined shape with count > 5 PHPStan seems to then believe that array_{shift,pop}() will always return a value from the array.

Code snippet that reproduces the problem

https://phpstan.org/r/090c443c-abb4-4bd4-a7cb-4bdc37f3d95d

Expected output

PHPStan shouldn't report any errors, like it does for the range a-d: https://phpstan.org/r/c77a36b5-49b7-498d-8499-67325939150b

Did PHPStan help you today? Did it make you happy in any way?

Created at 6 days ago
started
Created at 1 week ago
opened issue
`array_shift()` regression with some arrays

Bug report

PHPStan 1.8.2 didn't raise an error on this code but starting from 1.8.3 an error is raised, the rules for array_shift()/array_pop() no longer seem to understand that the array can be empty.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class HelloWorld
{
	/**
	 * @param array{name: string, age: int} $a
	 * @param array{name: string, age: int} $b
	 */
	public function compare(array $a, array $b): int
	{
		$sort = [
			$a['name'] <=> $b['name'],
			$a['age'] <=> $b['age'],
		];
		
		$sort = array_filter($sort, function (int $value): bool {
			return $value !== 0;
		});
		
		return array_shift($sort) ?? 0; // Error: Expression on left side of ?? is not nullable.
	}
}

https://phpstan.org/r/1dfa2673-c745-4d1b-9492-e50a6ab54eaa

Expected output

No error should be raised.

Did PHPStan help you today? Did it make you happy in any way?

Helps me write working code first time every day.

Created at 2 weeks ago
started
Created at 3 weeks ago
started
Created at 1 month ago
Plugin (still) fails to work with Composer < 2.3

Executing composer bin all install with Composer 2.2 fails as due to f0b48b5b4fbc13a49bc0d462ec518e27c1ed4ba8 and other changes.

PHP Fatal error:  Uncaught Error: Undefined class constant 'SUCCESS' in /tmp/tmp.iXBtOtyjej/vendor/bamarni/composer-bin-plugin/src/Command/BinCommand.php:161
Stack trace:
#0 /tmp/tmp.iXBtOtyjej/vendor/bamarni/composer-bin-plugin/src/Command/BinCommand.php(133): Bamarni\Composer\Bin\Command\BinCommand->executeAllNamespaces('/tmp/tmp.iXBtOt...', 'vendor-bin', Object(Symfony\Component\Console\Input\StringInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Command/Command.php(245): Bamarni\Composer\Bin\Command\BinCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Application.php(835): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Application.php(185): S in /tmp/tmp.iXBtOtyjej/vendor/bamarni/composer-bin-plugin/src/Command/BinCommand.php on line 161
Created at 2 months ago
Plugin fails to work with Composer < 2.3

This plugin can no longer be used with Composer 2.2 even though the composer.json says it's compatible, due to https://github.com/bamarni/composer-bin-plugin/pull/86

PHP Fatal error:  Uncaught Error: Call to undefined method Bamarni\Composer\Bin\BinCommand::requireComposer() in /tmp/tmp.Kzy6XI6bnx/vendor/bamarni/composer-bin-plugin/src/BinCommand.php:91
Stack trace:
#0 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Command/Command.php(245): Bamarni\Composer\Bin\BinCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Application.php(835): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///usr/local/lib/composer-2.2.14/vendor/symfony/console/Application.php(185): Symfony\Component\Console\Application->doRunCommand(Object(Bamarni\Composer\Bin\BinCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///usr/local/lib/composer-2.2.14/src/Composer/Console/Application.p in /tmp/tmp.Kzy6XI6bnx/vendor/bamarni/composer-bin-plugin/src/BinCommand.php on line 91
Created at 2 months ago