psalm-plugin-symfony icon indicating copy to clipboard operation
psalm-plugin-symfony copied to clipboard

Plugin caused problem with asserting type

Open pplotka opened this issue 3 years ago • 1 comments

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();
  • $formAttribute is Symfony Form type
  • ProductAttributeValueInterface::getAttribute(): ProducttttributeInterface
  • Assert::isInstanceOf is from https://github.com/webmozarts/assert

When I disable this plugin Psalm can inherit type correctly.

pplotka avatar Jan 10 '22 14:01 pplotka

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{}

zmitic avatar Jan 10 '22 15:01 zmitic