phpstan / phpstan-webmozart-assert

PHPStan extension for webmozart/assert
160 stars 27 forks source link

Issue with `implementsInterface` #150

Closed VincentLanglet closed 1 year ago

VincentLanglet commented 1 year ago

With the following code

foreach ($data['sniffs'] as $sniffName) {
     Assert::string($sniffName);
     Assert::classExists($sniffName);
     Assert::implementsInterface($sniffName, SniffInterface::class);

     $ruleSet->addSniff(new $sniffName());
}

I get

Call to static method Webmozart\Assert\Assert::implementsInterface() with class-string and 'TwigCsFixer\\Sniff\\SniffInterface' will always evaluate to false.

i tried to install

"phpstan/phpstan": "1.9.x-dev as 1.9.0",
"phpstan/phpstan-webmozart-assert": "1.2.x-dev as 1.3",

but it doesn't solved anything

I saw you recently work on this method @herndlm (https://github.com/phpstan/phpstan-webmozart-assert/pull/144), any idea what could be wrong here ?

herndlm commented 1 year ago

$data['sniffs'] is just mixed[] I presume?

herndlm commented 1 year ago

ah wait, but my changes are still unreleased. that means most likely that https://github.com/phpstan/phpstan-webmozart-assert/blob/1.2.1/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php#L454-L456 is the reason with the released version and, since you also get it with 1.2.x, subclassOf might be the problem afterwards. strange

I'll have to re-create this in a test and debug later.

VincentLanglet commented 1 year ago

$data['sniffs'] is just mixed[] I presume?

Yes, I have previous checks

Assert::isArray($data);
Assert::keyExists($data, 'sniffs');
Assert::isArray($data['sniffs']);

ah wait, but my changes are still unreleased. that means most likely that https://github.com/phpstan/phpstan-webmozart-assert/blob/1.2.1/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php#L454-L456 is the reason with the released version and, since you also get it with 1.2.x, subclassOf might be the problem afterwards. strange

I'll have to re-create this in a test and debug later.

Dunno if it help, but

Assert::isAOf($sniffName, SniffInterface::class);

is working fine

herndlm commented 1 year ago

interestingly my test cases are green here, can you check the linked PR if you do anything different or I missed anything? I'm both asserting types and doing the impossible checks with strict rules on 🤔

VincentLanglet commented 1 year ago

Dunno if it can help you, but my error is on an open source project: https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/src/Cache/CacheEncoder.php#L40 ignored here: https://github.com/VincentLanglet/Twig-CS-Fixer/blob/main/phpstan.neon#L40

herndlm commented 1 year ago

I think this was fixed on develop. I know you wrote you tested it, but I could verify that it errors exactly like that if I revert a specific commit

VincentLanglet commented 1 year ago

I think this was fixed on develop

I just tried again, and indeed I don't have the error with

        "phpstan/phpstan": "1.9.x-dev as 1.9.0",
        "phpstan/phpstan-webmozart-assert": "1.2.x-dev as 1.2.2",

I dunno how I messed up the first time. Sorry for the inconvenient.

herndlm commented 1 year ago

no worries, a double-check and another test case here don't hurt :)

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.