-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Update PHPStan #2231
Update PHPStan #2231
Conversation
@@ -232,6 +226,8 @@ private function parseDotSyntaxForPrimer(string $fieldName, ClassMetadata $class | |||
|
|||
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; | |||
} | |||
|
|||
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not enough knowledge about this, I've just added the same line than
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, an exception would be better if this should never be reached. This should read just fine:
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; | |
throw new \LogicException('Unable to parse property path for ReferencePrimer. Please report an issue in Doctrine\'s MongoDB ODM.'); |
@franmomu would it be possible for you to split this PR into two? First adding PHPStan (version currently used by us) as a GA and a second PR updating PHPStan, levels, and code to fix new faults? I'd definitely would like to merge PHPStan as a GA faster and solve new issues later :) |
All righty with #2236 merged we can now move this one forward. Please ping me when the branch is rebased, we'll be able to see results in GA now thanks to you :) |
6e37360
to
3e6c5e1
Compare
3e6c5e1
to
a2de76e
Compare
An exception is thrown in the line above.
a2de76e
to
165cb9e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left few remarks. Thanks @franmomu for all the work you do for ODM!
@@ -310,8 +313,7 @@ public function getDocumentDatabase(string $className) : Database | |||
return $this->documentDatabases[$className]; | |||
} | |||
|
|||
$metadata = $this->metadataFactory->getMetadataFor($className); | |||
assert($metadata instanceof ClassMetadata); | |||
$metadata = $this->getClassMetadata($className); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not using getClassMetadata
was an intentional micro-optimization to avoid an additional method call. I'm not sure it is still relevant in 2020 but better safe than sorry and I'd prefer keeping it
lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php
Outdated
Show resolved
Hide resolved
@@ -222,14 +222,12 @@ public function executeInserts(array $options = []) : void | |||
$inserts[] = $data; | |||
} | |||
|
|||
if ($inserts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity: PHPStan detected this if
as redundant as its value is basing on queuedInserts
which is already checked at the beginning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it! https://phpstan.org/r/07684e38-4e79-4aa7-b6ba-500c27da21c3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
@@ -232,6 +226,8 @@ private function parseDotSyntaxForPrimer(string $fieldName, ClassMetadata $class | |||
|
|||
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; | |||
} | |||
|
|||
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, an exception would be better if this should never be reached. This should read just fine:
return ['fieldName' => $fieldName, 'class' => $class, 'documents' => $documents, 'mapping' => $mapping]; | |
throw new \LogicException('Unable to parse property path for ReferencePrimer. Please report an issue in Doctrine\'s MongoDB ODM.'); |
The current return types did not comply with PersistentCollectionInterface.
The phpdoc did not match the current return and arguments types.
The check removed was impossible to be true since the argument has a type declaration.
The ReferencePrimer::parseDotSyntaxForPrimer had a case which there was no return and the function has to return an array or Traversable.
At the beginning of the method, "$this->queuedInserts" is checked if it is empty, if it is not, "$inserts" variable will always have some value and the "if" removed is always true.
165cb9e
to
e718fcc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fixes!
You've very welcome @malarzm! Happy to help |
Summary
The PHPStan version was almost 2 year old. With the new version I had to lower the level to 5 because more than 900 errors appear in level 7.
I didn't know how to solve some of the errors so I ignored them, I'll be happy to solve them and remove them from the ignore list.
PR with the Github Action: franmomu#5