psalm-plugin-symfony
psalm-plugin-symfony copied to clipboard
Plugin caused problem with asserting type
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();
$formAttributeis Symfony Form type- ProductAttributeValueInterface::getAttribute(): ProducttttributeInterface
Assert::isInstanceOfis from https://github.com/webmozarts/assert
When I disable this plugin Psalm can inherit type correctly.
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{}