Skip to content

Commit 953815f

Browse files
authored
Upgrade to PHPStan 2.1 (#2761)
* Upgrade to PHPStan 1.12 * Ensure we don't have phpstan deprecation * [doc] Set TKey type on Collection https://github.com/doctrine/collections/blob/2eb07e5953eed811ce1b309a7478a3b236f2273d/src/Collection.php#L29 * Upgrade to phpstan 2 * Run PHPStan on PHP 8.4 * PersistentCollections is not always present 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 (?) * Keep type assertions even when type is declared * Use @param-out for by-reference parameter phpstan/phpstan#10823 * Set properties to null instead of unset, as property hooks could be used in child classes * Fix generic types * Fix property.unusedType on private collection property * Fix type of $visited parameter set by-reference, changed since we use spl_object_id * ReflectionProperty::isInitialized() is always available since PHP 8.4 * Ignore missingType.generics on UnitOfWork::$persisters It should be a class-string-map, but not supported by phpstan phpstan/phpstan#9521 * Don't check Metadata generic type * Ignore arguments.count error on method calls with variable name * Update baseline * Fix type of Profile::$profileId * Remove incorrect @throw annotation * Make Expr constructor final, as it is instanciated with new static
1 parent a07b902 commit 953815f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1325
-353
lines changed

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
php-version:
19-
- "8.2"
19+
- "8.4"
2020

2121
steps:
2222
- name: "Checkout code"

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@
4444
"doctrine/orm": "^3.2",
4545
"jmikola/geojson": "^1.0",
4646
"phpbench/phpbench": "^1.0.0",
47-
"phpstan/phpstan": "~1.10.67",
48-
"phpstan/phpstan-phpunit": "^1.0",
47+
"phpstan/phpstan": "^2.1",
48+
"phpstan/phpstan-deprecation-rules": "^2.0",
49+
"phpstan/phpstan-phpunit": "^2.0",
4950
"phpunit/phpunit": "^10.4",
5051
"squizlabs/php_codesniffer": "^3.5",
5152
"symfony/cache": "^5.4 || ^6.0 || ^7.0"

docs/en/cookbook/lookup-reference.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ and a date.
6868
#[Field(type: 'date_immutable')]
6969
public DateTimeImmutable $date;
7070
71-
/** @var Collection<Item> */
71+
/** @var Collection<int, Item> */
7272
#[ReferenceMany(
7373
targetDocument: Item::class,
7474
cascade: 'all',
@@ -378,7 +378,7 @@ You need to create a new class to hold the result of the aggregation.
378378
#[Field(type: 'date_immutable')]
379379
public DateTimeImmutable $date;
380380
381-
/** @var Collection<Item> */
381+
/** @var Collection<int, Item> */
382382
#[EmbedMany(targetDocument: Item::class)]
383383
public Collection $items;
384384
@@ -631,7 +631,7 @@ but not the user.
631631
#[Field(type: 'string')]
632632
public string $name;
633633
634-
/** @var Collection<UserOrderResult> */
634+
/** @var Collection<int, UserOrderResult> */
635635
#[EmbedMany(targetDocument: UserOrderResult::class)]
636636
public Collection $orders;
637637
}
@@ -645,7 +645,7 @@ but not the user.
645645
#[Field(type: 'date_immutable')]
646646
public DateTimeImmutable $date;
647647
648-
/** @var Collection<Item> */
648+
/** @var Collection<int, Item> */
649649
#[EmbedMany(targetDocument: Item::class)]
650650
public Collection $items;
651651
}

docs/en/cookbook/simple-search-engine.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Now you can embed the ``Keyword`` document many times in the ``Product``:
141141
{
142142
// ...
143143
144-
/** @var Collection<Keyword> */
144+
/** @var Collection<int, Keyword> */
145145
#[EmbedMany(targetDocument: Keyword::class)]
146146
public Collection $keywords;
147147

docs/en/reference/aggregation-stage-reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pipeline stages. Take the following relationship for example:
381381
382382
class Orders
383383
{
384-
/** @var Collection<Item> */
384+
/** @var Collection<int, Item> */
385385
#[ReferenceMany(
386386
targetDocument: Item::class,
387387
cascade: 'all',

docs/en/reference/attributes-reference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ Optional arguments:
217217
218218
class User
219219
{
220-
/** @var Collection<BookTag|SongTag> */
220+
/** @var Collection<int, BookTag|SongTag> */
221221
#[EmbedMany(
222222
strategy:'set',
223223
discriminatorField:'type',
@@ -987,7 +987,7 @@ Optional arguments:
987987
988988
class User
989989
{
990-
/** @var Collection<Item> */
990+
/** @var Collection<int, Item> */
991991
#[ReferenceMany(
992992
strategy: 'set',
993993
targetDocument: Item::class,

docs/en/reference/bidirectional-references.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ and changes are tracked and persisted separately. Here is an example:
2323
{
2424
// ...
2525
26-
/** @var Collection<BlogPost> */
26+
/** @var Collection<int, BlogPost> */
2727
#[ReferenceMany(targetDocument: BlogPost::class)]
2828
private Collection $posts;
2929
}
@@ -66,7 +66,7 @@ One to Many
6666
{
6767
// ...
6868
69-
/** @var Collection<BlogPost> */
69+
/** @var Collection<int, BlogPost> */
7070
#[ReferenceMany(targetDocument: BlogPost::class, mappedBy: 'user')]
7171
private Collection $posts;
7272
}
@@ -189,11 +189,11 @@ Self-Referencing Many to Many
189189
{
190190
// ...
191191
192-
/** @var Collection<User> */
192+
/** @var Collection<int, User> */
193193
#[ReferenceMany(targetDocument: User::class, mappedBy: 'myFriends')]
194194
public Collection $friendsWithMe;
195195
196-
/** @var Collection<User> */
196+
/** @var Collection<int, User> */
197197
#[ReferenceMany(targetDocument: User::class, inversedBy: 'friendsWithMe')]
198198
public Collection $myFriends;
199199

docs/en/reference/complex-references.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ querying by the BlogPost's ID.
3535
{
3636
// ...
3737
38-
/** @var Collection<Comment> */
38+
/** @var Collection<int, Comment> */
3939
#[ReferenceMany(targetDocument: Comment::class, mappedBy: 'blogPost')]
4040
private Collection $comments;
4141
42-
/** @var Collection<Comment> */
42+
/** @var Collection<int, Comment> */
4343
#[ReferenceMany(
4444
targetDocument: Comment::class,
4545
mappedBy: 'blogPost',
@@ -88,7 +88,7 @@ administrators:
8888
8989
class BlogPost
9090
{
91-
/** @var Collection<Comment> */
91+
/** @var Collection<int, Comment> */
9292
#[ReferenceMany(
9393
targetDocument: Comment::class,
9494
mappedBy: 'blogPost',
@@ -109,7 +109,7 @@ call on the Comment repository class to populate the reference.
109109
110110
class BlogPost
111111
{
112-
/** @var Collection<Comment> */
112+
/** @var Collection<int, Comment> */
113113
#[ReferenceMany(
114114
targetDocument: Comment::class,
115115
mappedBy: 'blogPost',

docs/en/reference/custom-collections.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ persistence-related features.
2020
{
2121
// ...
2222
23-
/** @var Collection<Section> */
23+
/** @var Collection<int, Section> */
2424
#[EmbedMany(targetDocument: Section::class)]
2525
public Collection $sections;
2626
@@ -55,7 +55,7 @@ and ensuring that your custom class is initialized in the owning class' construc
5555
{
5656
// ...
5757
58-
/** @var Collection<Section> */
58+
/** @var Collection<int, Section> */
5959
#[EmbedMany(
6060
collectionClass: SectionCollection::class,
6161
targetDocument: Section::class,

docs/en/reference/embedded-mapping.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Embed many documents:
7373
{
7474
// ...
7575
76-
/** @var Collection<PhoneNumber> */
76+
/** @var Collection<int, PhoneNumber> */
7777
#[EmbedMany(targetDocument: Phonenumber::class)]
7878
private Collection $phoneNumbers;
7979
@@ -283,7 +283,7 @@ You can achieve this behavior by using the `storeEmptyArray` option for embedded
283283
{
284284
// ...
285285
286-
/** @var Collection<PhoneNumber> */
286+
/** @var Collection<int, PhoneNumber> */
287287
#[EmbedMany(targetDocument: PhoneNumber::class, storeEmptyArray: true)]
288288
private Collection $phoneNumbers;
289289
// ...

0 commit comments

Comments
 (0)