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

Use psalm errorLevel 3 #169

Merged
merged 3 commits into from
Apr 22, 2021
Merged

Use psalm errorLevel 3 #169

merged 3 commits into from
Apr 22, 2021

Conversation

franmomu
Copy link
Contributor

Another part from #159

Some methods are able to handle classname and classname alias, so
they could receive a class-string or a string. Adding phpdoc to
the variables makes psalm able to understand them.
@@ -22,7 +22,7 @@ public function __construct(ObjectManager $wrapped)

class ObjectManagerDecoratorTest extends TestCase
{
/** @var MockObject|ObjectManager */
/** @var MockObject&ObjectManager */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About this, it was included in PHPStorm apparently in 2018:https://blog.jetbrains.com/phpstorm/2018/09/phpstorm-2018-3-eap-183-2635-12/

Let me now if we should use @psalm-var.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPStorm indeed added parsing for it in 2.018 (it was still treating it as a union type internally as it did not support intersection types, but that's not a reason to avoid it in favor of writing a union type directly).

So +1 from me

psalm.xml Outdated
Comment on lines 42 to 48
<PossiblyNullReference>
<errorLevel type="suppress">
<!-- ReflectionProperty::getType() can return null, but there is ReflectionProperty::hasType()
check before -->
<file name="lib/Doctrine/Persistence/Reflection/TypedNoDefaultReflectionProperty.php"/>
</errorLevel>
</PossiblyNullReference>
Copy link
Contributor Author

@franmomu franmomu Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For things like this that can be fixed in next psalm releases, can we maybe use annotations (@psalm-suppress) so we can enable findUnusedPsalmSuppress and if this is fixed, psalm would warn us.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please!

Copy link
Contributor Author

@franmomu franmomu Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I added this PossiblyNullReference in the first place because locally I used vendor/bin/psalm --no-cache --php-version=7.4 and running that command it throws the PossiblyNullReference.

But since we are not specifying the php version here, I think it's using the lowest one from composer.json, 7.1 and using that one there is no error.

@@ -1,8 +1,7 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire
Copy link
Member

@orklah please review 🙂

@@ -62,6 +62,8 @@ public function getClassNamespace($class)

/**
* {@inheritDoc}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this works properly? I have a vague memory if reading that inheritDoc was ignored by Psalm when there was other tags in the block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I thought it read both since I got some other error about instantiating ReflectionClass, I've added the other tags.

This includes:
  - adding assertions to avoid nullable values
  - Override phpdoc to be more specific

Apart from ignore some issues.
@greg0ire greg0ire merged commit 2e87a31 into doctrine:2.2.x Apr 22, 2021
@greg0ire greg0ire added this to the 2.2.0 milestone Apr 22, 2021
@greg0ire
Copy link
Member

Thanks @franmomu !

@franmomu franmomu deleted the use_psalm_3 branch April 22, 2021 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants