Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin caused problem with asserting type #236

Open
pplotka opened this issue Jan 10, 2022 · 1 comment
Open

Plugin caused problem with asserting type #236

pplotka opened this issue Jan 10, 2022 · 1 comment

Comments

@pplotka
Copy link

pplotka commented Jan 10, 2022

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
Copy link
Contributor

zmitic commented Jan 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants