Skip to content

Commit 1d6f9bd

Browse files
mbabkerphansys
authored andcommitted
Upgrade to PHPStan 2.0
1 parent 16ab390 commit 1d6f9bd

File tree

83 files changed

+932
-530
lines changed

Some content is hidden

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

83 files changed

+932
-530
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@
6060
"doctrine/orm": "^2.14.0 || ^3.0",
6161
"friendsofphp/php-cs-fixer": "^3.14.0",
6262
"nesbot/carbon": "^2.71 || ^3.0",
63-
"phpstan/phpstan": "^1.11",
64-
"phpstan/phpstan-doctrine": "^1.4",
65-
"phpstan/phpstan-phpunit": "^1.4",
63+
"phpstan/phpstan": "^2.1.1",
64+
"phpstan/phpstan-doctrine": "^2.0.1",
65+
"phpstan/phpstan-phpunit": "^2.0.3",
6666
"phpunit/phpunit": "^9.6",
67-
"rector/rector": "^1.1",
67+
"rector/rector": "^2.0.6",
6868
"symfony/console": "^5.4 || ^6.0 || ^7.0",
6969
"symfony/doctrine-bridge": "^5.4 || ^6.0 || ^7.0",
7070
"symfony/phpunit-bridge": "^6.0 || ^7.0",

phpstan-baseline.neon

Lines changed: 548 additions & 214 deletions
Large diffs are not rendered by default.

phpstan.neon.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ parameters:
1212
- tests/bootstrap.php
1313
treatPhpDocTypesAsCertain: false
1414
ignoreErrors:
15+
-
16+
identifier: trait.unused
1517
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
1618
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
1719
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
1820
- '#^Method Gedmo\\(?:[^\\]+\\)*Mapping\\Driver[^:]+::readExtendedMetadata\(\) with return type void returns [\w\|<>\s,]+ but should not return anything\.$#'
19-
- '#^Method Gedmo\\Uploadable\\Mapping\\Validator::validateConfiguration\(\) with return type void returns array<string, mixed> but should not return anything\.$#'
20-
- '#^Result of static method Gedmo\\Uploadable\\Mapping\\Validator::validateConfiguration\(\) \(void\) is used\.$#'
2121
- '#^Result of method Gedmo\\Mapping\\Driver::readExtendedMetadata\(\) \(void\) is used\.$#'
2222
excludePaths:
2323
# Deprecated and unused class, interface does not exist as of 4.0

src/AbstractTrackingListener.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
/**
2929
* The AbstractTrackingListener provides generic functions for all listeners.
3030
*
31-
* @phpstan-template TConfig of array
32-
* @phpstan-template TEventAdapter of AdapterInterface
31+
* @template TConfig of array
32+
* @template TEventAdapter of AdapterInterface
3333
*
34-
* @phpstan-extends MappedEventSubscriber<TConfig, TEventAdapter>
34+
* @template-extends MappedEventSubscriber<TConfig, TEventAdapter>
3535
*
3636
* @author Gediminas Morkevicius <[email protected]>
3737
*/
@@ -207,9 +207,9 @@ public function prePersist(EventArgs $args)
207207
/**
208208
* Get the value for an updated field.
209209
*
210-
* @param ClassMetadata $meta
211-
* @param string $field
212-
* @param AdapterInterface $eventAdapter
210+
* @param ClassMetadata<object> $meta
211+
* @param string $field
212+
* @param TEventAdapter $eventAdapter
213213
*
214214
* @return mixed
215215
*/
@@ -218,10 +218,10 @@ abstract protected function getFieldValue($meta, $field, $eventAdapter);
218218
/**
219219
* Updates a field.
220220
*
221-
* @param object $object
222-
* @param AdapterInterface $eventAdapter
223-
* @param ClassMetadata $meta
224-
* @param string $field
221+
* @param object $object
222+
* @param TEventAdapter $eventAdapter
223+
* @param ClassMetadata<object> $meta
224+
* @param string $field
225225
*
226226
* @return void
227227
*/

src/Blameable/BlameableListener.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class BlameableListener extends AbstractTrackingListener
3434
/**
3535
* Get the user value to set on a blameable field
3636
*
37-
* @param ClassMetadata $meta
38-
* @param string $field
37+
* @param ClassMetadata<object> $meta
38+
* @param string $field
39+
* @param BlameableAdapter $eventAdapter
3940
*
4041
* @return mixed
4142
*/

src/Blameable/Mapping/Driver/Xml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function readExtendedMetadata($meta, array &$config)
119119
/**
120120
* Checks if $field type is valid
121121
*
122-
* @param ClassMetadata $meta
123-
* @param string $field
122+
* @param ClassMetadata<object> $meta
123+
* @param string $field
124124
*
125125
* @return bool
126126
*/

src/Blameable/Mapping/Driver/Yaml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ protected function _loadMappingFile($file)
125125
/**
126126
* Checks if $field type is valid
127127
*
128-
* @param ClassMetadata $meta
129-
* @param string $field
128+
* @param ClassMetadata<object> $meta
129+
* @param string $field
130130
*
131131
* @return bool
132132
*/

src/IpTraceable/IpTraceableListener.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Gedmo\AbstractTrackingListener;
1414
use Gedmo\Exception\InvalidArgumentException;
1515
use Gedmo\IpTraceable\Mapping\Event\IpTraceableAdapter;
16-
use Gedmo\Mapping\Event\AdapterInterface;
1716

1817
/**
1918
* The IpTraceable listener handles the update of
@@ -35,9 +34,9 @@ class IpTraceableListener extends AbstractTrackingListener
3534
/**
3635
* Get the ipValue value to set on a ip field
3736
*
38-
* @param ClassMetadata $meta
39-
* @param string $field
40-
* @param AdapterInterface $eventAdapter
37+
* @param ClassMetadata<object> $meta
38+
* @param string $field
39+
* @param IpTraceableAdapter $eventAdapter
4140
*
4241
* @return string|null
4342
*/

src/IpTraceable/Mapping/Driver/Xml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public function readExtendedMetadata($meta, array &$config)
121121
/**
122122
* Checks if $field type is valid
123123
*
124-
* @param ClassMetadata $meta
125-
* @param string $field
124+
* @param ClassMetadata<object> $meta
125+
* @param string $field
126126
*
127127
* @return bool
128128
*/

src/IpTraceable/Mapping/Driver/Yaml.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ protected function _loadMappingFile($file)
121121
/**
122122
* Checks if $field type is valid
123123
*
124-
* @param ClassMetadata $meta
125-
* @param string $field
124+
* @param ClassMetadata<object> $meta
125+
* @param string $field
126126
*
127127
* @return bool
128128
*/

src/Loggable/Entity/Repository/LogEntryRepository.php

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,25 @@
2525
*
2626
* @author Gediminas Morkevicius <[email protected]>
2727
*
28-
* @phpstan-template T of Loggable|object
28+
* @template T of Loggable|object
2929
*
30-
* @phpstan-extends EntityRepository<AbstractLogEntry<T>>
30+
* @template-extends EntityRepository<AbstractLogEntry<T>>
3131
*/
3232
class LogEntryRepository extends EntityRepository
3333
{
3434
/**
3535
* Currently used loggable listener
3636
*
37-
* @phpstan-var LoggableListener<T>|null
37+
* @var LoggableListener<T>|null
3838
*/
3939
private ?LoggableListener $listener = null;
4040

4141
/**
4242
* Loads all log entries for the given entity
4343
*
44-
* @param object $entity
44+
* @param T $entity
4545
*
46-
* @return AbstractLogEntry[]
47-
*
48-
* @phpstan-param T $entity
49-
*
50-
* @phpstan-return array<array-key, AbstractLogEntry<T>>
46+
* @return array<array-key, AbstractLogEntry<T>>
5147
*/
5248
public function getLogEntries($entity)
5349
{
@@ -57,11 +53,9 @@ public function getLogEntries($entity)
5753
/**
5854
* Get the query for loading of log entries
5955
*
60-
* @param object $entity
56+
* @param T $entity
6157
*
6258
* @return Query
63-
*
64-
* @phpstan-param T $entity
6559
*/
6660
public function getLogEntriesQuery($entity)
6761
{
@@ -89,14 +83,12 @@ public function getLogEntriesQuery($entity)
8983
* After this operation you will need to
9084
* persist and flush the $entity.
9185
*
92-
* @param object $entity
93-
* @param int $version
86+
* @param T $entity
87+
* @param int $version
9488
*
9589
* @throws UnexpectedValueException
9690
*
9791
* @return void
98-
*
99-
* @phpstan-param T $entity
10092
*/
10193
public function revert($entity, $version = 1)
10294
{
@@ -151,12 +143,11 @@ public function revert($entity, $version = 1)
151143
}
152144

153145
/**
154-
* @param string $field
155-
* @param mixed $value
146+
* @param ClassMetadata<T> $objectMeta
147+
* @param string $field
148+
* @param mixed $value
156149
*
157150
* @return void
158-
*
159-
* @phpstan-param ClassMetadata<T> $objectMeta
160151
*/
161152
protected function mapValue(ClassMetadata $objectMeta, $field, &$value)
162153
{
@@ -173,7 +164,7 @@ protected function mapValue(ClassMetadata $objectMeta, $field, &$value)
173164
*
174165
* @throws RuntimeException if listener is not found
175166
*
176-
* @phpstan-return LoggableListener<T>
167+
* @return LoggableListener<T>
177168
*/
178169
private function getLoggableListener(): LoggableListener
179170
{

src/Loggable/LoggableListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* versioned?: string[],
3535
* }
3636
*
37-
* @phpstan-template T of Loggable|object
37+
* @template T of Loggable|object
3838
*
3939
* @phpstan-extends MappedEventSubscriber<LoggableConfiguration, LoggableAdapter>
4040
*/

src/Loggable/Mapping/Driver/Attribute.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Gedmo\Loggable\Mapping\Driver;
1111

1212
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata as ClassMetadataODM;
13+
use Doctrine\ORM\Mapping\ClassMetadata as ClassMetadataORM;
1314
use Doctrine\Persistence\Mapping\ClassMetadata;
1415
use Gedmo\Exception\InvalidMappingException;
1516
use Gedmo\Mapping\Annotation\Loggable;
@@ -38,7 +39,7 @@ class Attribute extends AbstractAnnotationDriver
3839

3940
public function validateFullMetadata(ClassMetadata $meta, array $config)
4041
{
41-
if ($config && $meta instanceof ClassMetadataODM && is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) {
42+
if ($config && $meta instanceof ClassMetadataODM && count($meta->getIdentifier()) > 1) {
4243
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->getName()}");
4344
}
4445

@@ -94,7 +95,7 @@ public function readExtendedMetadata($meta, array &$config)
9495
}
9596

9697
if (!$meta->isMappedSuperclass && $config) {
97-
if ($meta instanceof ClassMetadataODM && is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) {
98+
if ($meta instanceof ClassMetadataODM && count($meta->getIdentifier()) > 1) {
9899
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->getName()}");
99100
}
100101

@@ -107,7 +108,8 @@ public function readExtendedMetadata($meta, array &$config)
107108
}
108109

109110
/**
110-
* @param string $field
111+
* @param ClassMetadata<object> $meta
112+
* @param string $field
111113
*
112114
* @return bool
113115
*/
@@ -117,7 +119,8 @@ protected function isMappingValid(ClassMetadata $meta, $field)
117119
}
118120

119121
/**
120-
* @param array<string, mixed> $config
122+
* @param ClassMetadata<object> $meta
123+
* @param array<string, mixed> $config
121124
*
122125
* @return bool
123126
*/
@@ -129,9 +132,10 @@ protected function isClassAnnotationInValid(ClassMetadata $meta, array &$config)
129132
/**
130133
* Searches properties of embedded objects for versioned fields
131134
*
132-
* @param array<string, mixed> $config
135+
* @param array<string, mixed> $config
136+
* @param ClassMetadataORM<object> $meta
133137
*/
134-
private function inspectEmbeddedForVersioned(string $field, array &$config, \Doctrine\ORM\Mapping\ClassMetadata $meta): void
138+
private function inspectEmbeddedForVersioned(string $field, array &$config, ClassMetadataORM $meta): void
135139
{
136140
$class = new \ReflectionClass($meta->embeddedClasses[$field]['class']);
137141

src/Loggable/Mapping/Driver/Xml.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function readExtendedMetadata($meta, array &$config)
4141
if (in_array($xmlDoctrine->getName(), ['mapped-superclass', 'entity', 'document'], true)) {
4242
if (isset($xml->loggable)) {
4343
/**
44-
* @var \SimpleXMLElement;
44+
* @var \SimpleXMLElement
4545
*/
4646
$data = $xml->loggable;
4747
$config['loggable'] = true;
@@ -75,7 +75,7 @@ public function readExtendedMetadata($meta, array &$config)
7575
}
7676

7777
if (!$meta->isMappedSuperclass && $config) {
78-
if ($meta instanceof ClassMetadataODM && is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) {
78+
if ($meta instanceof ClassMetadataODM && count($meta->getIdentifier()) > 1) {
7979
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->getName()}");
8080
}
8181
if (isset($config['versioned']) && !isset($config['loggable'])) {
@@ -89,7 +89,8 @@ public function readExtendedMetadata($meta, array &$config)
8989
/**
9090
* Searches mappings on element for versioned fields
9191
*
92-
* @param array<string, mixed> $config
92+
* @param array<string, mixed> $config
93+
* @param ClassMetadata<object> $meta
9394
*
9495
* @return array<string, mixed>
9596
*/

src/Loggable/Mapping/Driver/Yaml.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function readExtendedMetadata($meta, array &$config)
125125
}
126126

127127
if (!$meta->isMappedSuperclass && $config) {
128-
if ($meta instanceof ClassMetadata && is_array($meta->getIdentifier()) && count($meta->getIdentifier()) > 1) {
128+
if ($meta instanceof ClassMetadata && count($meta->getIdentifier()) > 1) {
129129
throw new InvalidMappingException("Loggable does not support composite identifiers in class - {$meta->getName()}");
130130
}
131131
if (isset($config['versioned']) && !isset($config['loggable'])) {

src/Loggable/Mapping/Event/Adapter/ODM.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace Gedmo\Loggable\Mapping\Event\Adapter;
1111

12+
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1213
use Gedmo\Loggable\Document\LogEntry;
1314
use Gedmo\Loggable\Mapping\Event\LoggableAdapter;
1415
use Gedmo\Mapping\Event\Adapter\ODM as BaseAdapterODM;
@@ -26,11 +27,17 @@ public function getDefaultLogEntryClass()
2627
return LogEntry::class;
2728
}
2829

30+
/**
31+
* @param ClassMetadata<object> $meta
32+
*/
2933
public function isPostInsertGenerator($meta)
3034
{
3135
return false;
3236
}
3337

38+
/**
39+
* @param ClassMetadata<object> $meta
40+
*/
3441
public function getNewVersion($meta, $object)
3542
{
3643
$dm = $this->getObjectManager();

src/Loggable/Mapping/Event/Adapter/ORM.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ public function getDefaultLogEntryClass()
2929
}
3030

3131
/**
32-
* @param ClassMetadata $meta
32+
* @param ClassMetadata<object> $meta
3333
*/
3434
public function isPostInsertGenerator($meta)
3535
{
3636
return $meta->idGenerator->isPostInsertGenerator();
3737
}
3838

39+
/**
40+
* @param ClassMetadata<object> $meta
41+
*/
3942
public function getNewVersion($meta, $object)
4043
{
4144
$em = $this->getObjectManager();

0 commit comments

Comments
 (0)