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

Update PHPStan #2231

Merged
merged 7 commits into from
Nov 4, 2020
Merged

Update PHPStan #2231

merged 7 commits into from
Nov 4, 2020

Conversation

franmomu
Copy link
Contributor

Q A
Type improvement
BC Break no
Fixed issues

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

@@ -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];
Copy link
Contributor Author

@franmomu franmomu Oct 18, 2020

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];
. But since I guess this line is never reached, maybe an Exception would be better.

Copy link
Member

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:

Suggested change
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.');

@malarzm
Copy link
Member

malarzm commented Oct 24, 2020

@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 :)

@malarzm
Copy link
Member

malarzm commented Nov 3, 2020

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 :)

@franmomu franmomu changed the title Move PHPStan check to Github actions Update PHPStan Nov 4, 2020
@franmomu
Copy link
Contributor Author

franmomu commented Nov 4, 2020

hi @malarzm, can you please take a look whenever you can? I've also saw that PHPStan was not totally happy, I've created #2240 in the meanwhile if you want to have it green.

An exception is thrown in the line above.
Copy link
Member

@malarzm malarzm left a 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);
Copy link
Member

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

@@ -222,14 +222,12 @@ public function executeInserts(array $options = []) : void
$inserts[] = $data;
}

if ($inserts) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

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];
Copy link
Member

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:

Suggested change
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.
Copy link
Member

@malarzm malarzm left a 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!

@franmomu
Copy link
Contributor Author

franmomu commented Nov 4, 2020

You've very welcome @malarzm! Happy to help

@malarzm malarzm added the Task label Nov 4, 2020
@malarzm malarzm added this to the 2.1.3 milestone Nov 4, 2020
@malarzm malarzm merged commit 519403e into doctrine:2.1.x Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants