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 to PHPStan 2.0 #135

Closed
wants to merge 3 commits into from

Conversation

carlos-granados
Copy link
Contributor

Updates the code of this repository to be compatible with PHPStan 2.0, see the comments for more details

To work on this I had to disable the following dev dependencies:

  • rector/rector
  • tomasvotruba/type-coverage
  • symplify/phpstan-rules

Because they still depend on the old PHPStan 1.x. Once these dependencies get updated, this can be fully tested with them

@@ -20,8 +20,3 @@ parameters:
ignoreErrors:
-
identifier: missingType.generics

# overly detailed
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the doc comments in the tests, so this error does not show any more

@@ -53,8 +51,9 @@ public function processNode(Node $node, Scope $scope): ?array
}

$classType = $scope->getType($classAndMethodArrayExprs->getClassExpr());
if ($classType instanceof ConstantStringType) {
$className = $classType->getValue();
if (count($classType->getConstantStrings()) === 1) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PHPStan 2.0 throws an error if you use this instanceof ConstantStringType construction and they recommend that you use ->getConstantStrings() instead, see https://phpstan.org/blog/why-is-instanceof-type-wrong-and-getting-deprecated

Copy link
Contributor

@staabm staabm Dec 1, 2024

Choose a reason for hiding this comment

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

can/could/should we return multipe results when count($classType->getConstantStrings()) > 1 instead of discarding it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the class passed to a Symfony\Component\Validator\Constraints\Callback attribute instance. It cannot be multiple classes

Copy link
Contributor

Choose a reason for hiding this comment

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

I see 👍 - for attributes it makes sense.

src/Collectors/Callable_/CallUserFuncCollector.php Outdated Show resolved Hide resolved
src/Collectors/FormTypeClassCollector.php Show resolved Hide resolved
src/MethodTypeDetector.php Show resolved Hide resolved
src/Rules/UnusedPublicClassConstRule.php Show resolved Hide resolved
@@ -23,6 +23,10 @@

final class LocalOnlyPublicClassMethodRuleTest extends RuleTestCase
{
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

PHPStan 2 requires that these parameters have a more detailed type description

@staabm
Copy link
Contributor

staabm commented Dec 1, 2024

To work on this I had to disable the following dev dependencies:

* rector/rector

could use the rector RC release

@TomasVotruba
Copy link
Owner

Thank you Carlos!

I've rebased and cherry picked in #141

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

Successfully merging this pull request may close these issues.

4 participants