-
-
Notifications
You must be signed in to change notification settings - Fork 509
Upgrade to PHPStan 2.1 #2761
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
base: 2.12.x
Are you sure you want to change the base?
Upgrade to PHPStan 2.1 #2761
Conversation
Path "tests/PersistentCollections" is neither a directory, nor a file path, nor a fnmatch pattern. If the excluded path can sometimes exist, append (?) to its config entry to mark it as optional. Example: parameters: excludePaths: analyseAndScan: - tests/PersistentCollections (?)
…sed in child classes
It should be a class-string-map, but not supported by phpstan phpstan/phpstan#9521
@@ -68,7 +68,7 @@ and a date. | |||
#[Field(type: 'date_immutable')] | |||
public DateTimeImmutable $date; | |||
/** @var Collection<Item> */ | |||
/** @var Collection<int, Item> */ |
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.
Updating all doc examples, the Collection
class has 2 type templates.
@@ -60,7 +61,7 @@ class ParentObject | |||
#[ODM\Id] | |||
private $id; | |||
|
|||
/** @var Collection<int, ChildObject>|array<ChildObject> */ | |||
/** @var Collection<int, ChildObject> */ |
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.
Collection
was never instantiated; but I think that's the type used when the relation is hydrated from the database. So I changed line 100 to create an ArrayCollection
.
@@ -31,7 +30,7 @@ public function setUp(): void | |||
|
|||
public function tearDown(): void | |||
{ | |||
unset($this->driver); |
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.
PHPstan warns that the property may have hooks in the child classes, so unset
is not allowed.
Marking all test classes final
is an other option, but doesn't work when we need to extend it (AbstractDriverTestCase
). Just replacing with with a null
value to unset the object.
/** @phpstan-ignore missingType.generics, missingType.generics */ | ||
public function intersection(Collection&ArrayCollection $param): Collection&ArrayCollection |
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.
The code is repeated because the error is present twice: for the parameter and for the return type.
if (method_exists($prop, 'isInitialized') && ! $prop->isInitialized($document)) { | ||
if (! $prop->isInitialized($document)) { |
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.
ReflectionProperty::isInitialized
is always available since PHP 7.4, and we require PHP 8.1.
@@ -11,7 +11,7 @@ parameters: | |||
excludePaths: | |||
- tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/User.php | |||
- tests/Hydrators/ | |||
- tests/PersistentCollections/ | |||
- tests/PersistentCollections/ (?) |
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.
The directory doesn't exist before tests run, this syntax allows for missing directory path.
- message: '#with generic class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata does not specify its types: T$#' | ||
identifier: missingType.generics |
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.
The ClassMetadata
is always used in generic way. We would have to use ClassMetadata<object>
everywhere.
# To be removed when reaching phpstan level 6 | ||
checkMissingVarTagTypehint: true | ||
checkMissingTypehints: true | ||
checkMissingIterableValueType: true |
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.
This option was removed from PHPStan 2.
Summary
The upgrade is necessary because phpstan 1.10 that is currently has issues with PHP 8.4.