phpstan-symfony
phpstan-symfony copied to clipboard
DIC parameter is interpreted as *never*
Since commit https://github.com/phpstan/phpstan-symfony/commit/2063d60f1bfe97c5702a839b3bc68d7f3fa75318 I have a error that a dic parameter is never.
I am doing in the test code:
static::assertNotSame($this->container->getParameter('shopware.filesystem.public'), $this->container->getParameter('shopware.filesystem.theme'));
That both parameter keys which are arrays are the same. Since that commit I get
Parameter #1 $expected of static method PHPUnit\Framework\Assert::assertSame() contains unresolvable type.
I took the parameter out and "over-typed" it with an var annotation
/** @var array{type: string, config: array{root: string}} $filesystemPublic */
$filesystemPublic = $this->builder->getParameter('shopware.filesystem.public');
static::assertNotSame($filesystemPublic, $this->builder->getParameter('shopware.filesystem.theme'));
This produces that next strange error
72 Call to static method PHPUnit\Framework\Assert::assertSame() with *NEVER* and array{type: string, config: array{root: string}} will always evaluate to false.
72 Parameter #1 $expected of static method PHPUnit\Framework\Assert::assertSame() contains unresolvable type.
/cc @VincentLanglet
What is your config ? @shyim
I'll need more explanation about the shopware.filesystem.public.
Best would be to reproduce this error with the tests of this repository
Here you are :)
https://github.com/shopware/platform/blob/dea144715a735c2b6f53098b9c92f9eeebc16c21/src/Core/Framework/Test/DependencyInjection/CompilerPass/FilesystemConfigMigrationCompilerPassTest.php#L60
Here you are :)
https://github.com/shopware/platform/blob/dea144715a735c2b6f53098b9c92f9eeebc16c21/src/Core/Framework/Test/DependencyInjection/CompilerPass/FilesystemConfigMigrationCompilerPassTest.php#L60
I ran
git clone ...
composer install
php src/Core/DevOps/StaticAnalyze/PHPStan/phpstan-bootstrap.php
vendor/bin/phpstan analyse src/Core/Framework/Test/DependencyInjection/CompilerPass/FilesystemConfigMigrationCompilerPassTest.php
And got no error
@shyim clearly misunderstood what @VincentLanglet meant with "Best would be to reproduce this error with the tests of this repository".
@shyim clearly misunderstood what @VincentLanglet meant with "Best would be to reproduce this error with the tests of this repository".
Yes, but if I could have been able to reproduce the error with his repository, I would have write the fix/test by myself.
I'm fine with both solution. Either, I have an easy way to reproduce the error on his repository Either, you (@shyim) write a failing test phpstan/phpstan-symfony repository to reproduce the error you have, and I'll debug to fix it.
I think all you need to be able to fix this is to see how shopware.filesystem.public looks like in .yml or .xml container dump.
I reproduced the error with his repository.
I have
<parameter key="shopware.filesystem.public" type="collection">
<parameter key="type">local</parameter>
<parameter key="config" type="collection">
<parameter key="root">/Users/vincentl/Perso/platform/public</parameter>
</parameter>
</parameter>
<parameter key="shopware.filesystem.theme" type="collection">
<parameter key="type">local</parameter>
<parameter key="config" type="collection">
<parameter key="root">/Users/vincentl/Perso/platform/public</parameter>
</parameter>
</parameter>
And with the code
$this->builder->setParameter('shopware.filesystem.theme', ['foo' => 'foo']);
$this->builder->setParameter('shopware.filesystem.theme.type', 'amazon-s3');
$this->builder->setParameter('shopware.filesystem.theme.config', ['test' => 'test']);
$this->builder->setParameter('shopware.filesystem.theme.url', 'http://cdn.de');
$this->builder->compile();
\PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.public'));
\PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.theme'));
static::assertNotSame($this->builder->getParameter('shopware.filesystem.public'), $this->builder->getParameter('shopware.filesystem.theme'));
\PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.public'));
\PHPStan\dumpType($this->builder->getParameter('shopware.filesystem.theme'));
I have
58 Dumped type: array{type: string, config: array{root: string}}
59 Dumped type: array{type: string, config: array{root: string}}
63 Dumped type: array{type: string, config: array{root: string}}
64 Dumped type: array{type: string, config: array{root: string}}
68 Dumped type: *NEVER*
69 Dumped type: *NEVER*
Phpstan is thinking that the parameter are the same because it doesn't change the value with setParameter.
but Phpstan shouldn't even use the container xml here, since the test is doing new ContainerBuilder.
To simplify the issue
$builder = new ContainerBuilder();
\PHPStan\dumpType($builder->getParameter('shopware.filesystem.public'));
is reported by phpstan
Dumped type: array{type: string, config: array{root: string}}
To me this is wrong, but not related to my changes.
And it will require to consider differently Containerbuilder which are injected as a service, and ContainerBuilder which are freshly created. Doesn't seems like an easy issue to solve, but I may be wrong @ondrejmirtes.