psalm / psalm-plugin-symfony

Psalm Plugin for Symfony
MIT License
226 stars 53 forks source link

Plugin caused problem with asserting type #236

Open pplotka opened 2 years ago

pplotka commented 2 years ago

I use this plugin in the Sylius project, but this is not important (in my opinion).

$attributeValue = $formAttribute->getData();
Assert::isInstanceOf($attributeValue, ProductAttributeValueInterface::class);
$attribute = $attributeValue->getAttribute();

return (
    !$attribute->isTranslatable()
    ||
    $attributeValue->getLocaleCode() !== $this->localeProvider->getDefaultLocaleCode()
);

I got the error:

ERROR: MixedMethodCall - XXX - Cannot determine the type of $attribute when calling method isTranslatable (see https://psalm.dev/015)
            !$attribute->isTranslatable()

  The type of isTranslatable is sourced from here - XXX
        $attribute = $attributeValue->getAttribute();

When I disable this plugin Psalm can inherit type correctly.

zmitic commented 2 years ago

Check this file: https://github.com/psalm/psalm-plugin-symfony/blob/master/src/Stubs/common/Component/Form/FormInterface.stubphp#L14

Because forms are stubbed, psalm will think it is mixed.

Solution: just add @var for value.

Better way would be to tell psalm what kind of data you expect:

/** @extends AbstractType<ProductAttributeValueInterface> */
class YourFormType extends AbstractType{}