Skip to content

Commit 61c77d1

Browse files
committed
Fix generic type implementations
1 parent 85f7831 commit 61c77d1

30 files changed

+79
-29
lines changed

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ parameters:
1313
treatPhpDocTypesAsCertain: false
1414
checkMissingVarTagTypehint: true
1515
checkMissingTypehints: true
16-
# @todo: Remove the "checkGenericClassInNonGenericObjectType" definition.
17-
checkGenericClassInNonGenericObjectType: false
1816
ignoreErrors:
1917
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
2018
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'

src/AbstractTrackingListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function getSubscribedEvents()
4747
* Maps additional metadata for the object.
4848
*
4949
* @param LoadClassMetadataEventArgs $eventArgs
50+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
5051
*
5152
* @return void
5253
*/

src/Loggable/LoggableListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
namespace Gedmo\Loggable;
1111

1212
use Doctrine\Common\EventArgs;
13-
use Doctrine\ORM\Mapping\ClassMetadata;
13+
use Doctrine\ORM\Mapping\ClassMetadata as ORMClassMetadata;
1414
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
15+
use Doctrine\Persistence\Mapping\ClassMetadata;
1516
use Doctrine\Persistence\ObjectManager;
1617
use Gedmo\Exception\InvalidArgumentException;
1718
use Gedmo\Loggable\Entity\LogEntry;
@@ -125,6 +126,7 @@ public function getSubscribedEvents()
125126
* Maps additional metadata
126127
*
127128
* @param LoadClassMetadataEventArgs $eventArgs
129+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
128130
*
129131
* @return void
130132
*/
@@ -312,7 +314,7 @@ protected function createLogEntry($action, $object, LoggableAdapter $ea)
312314
if ($config = $this->getConfiguration($om, $meta->getName())) {
313315
$logEntryClass = $this->getLogEntryClass($ea, $meta->getName());
314316
$logEntryMeta = $om->getClassMetadata($logEntryClass);
315-
/** @var LogEntryInterface $logEntry */
317+
/** @var LogEntryInterface<T> $logEntry */
316318
$logEntry = $logEntryMeta->newInstance();
317319

318320
$logEntry->setAction($action);
@@ -322,7 +324,7 @@ protected function createLogEntry($action, $object, LoggableAdapter $ea)
322324

323325
// check for the availability of the primary key
324326
$uow = $om->getUnitOfWork();
325-
if (LogEntryInterface::ACTION_CREATE === $action && ($ea->isPostInsertGenerator($meta) || ($meta instanceof ClassMetadata && $meta->isIdentifierComposite))) {
327+
if (LogEntryInterface::ACTION_CREATE === $action && ($ea->isPostInsertGenerator($meta) || ($meta instanceof ORMClassMetadata && $meta->isIdentifierComposite))) {
326328
$this->pendingLogEntryInserts[spl_object_id($object)] = $logEntry;
327329
} else {
328330
$logEntry->setObjectId($wrapped->getIdentifier(false, true));

src/Mapping/Driver/AbstractAnnotationDriver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function setOriginalDriver($driver)
7979
* @param ClassMetadata $meta
8080
*
8181
* @return \ReflectionClass
82+
* @phpstan-return \ReflectionClass<object>
8283
*/
8384
public function getMetaReflectionClass($meta)
8485
{

src/Mapping/Driver/AttributeAnnotationReader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(AttributeReader $attributeReader, Reader $annotation
3737
}
3838

3939
/**
40+
* @phpstan-param \ReflectionClass<object> $class
41+
*
4042
* @return Annotation[]
4143
*/
4244
public function getClassAnnotations(\ReflectionClass $class): array
@@ -51,7 +53,10 @@ public function getClassAnnotations(\ReflectionClass $class): array
5153
}
5254

5355
/**
54-
* @param class-string<T> $annotationName the name of the annotation
56+
* @param string $annotationName
57+
*
58+
* @phpstan-param \ReflectionClass<object> $class
59+
* @phpstan-param class-string<T> $annotationName the name of the annotation
5560
*
5661
* @return T|null the Annotation or NULL, if the requested annotation does not exist
5762
*

src/Mapping/Driver/AttributeReader.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ final class AttributeReader
2222
private $isRepeatableAttribute = [];
2323

2424
/**
25+
* @phpstan-param \ReflectionClass<object> $class
26+
*
2527
* @return array<Annotation|Annotation[]>
2628
*/
2729
public function getClassAnnotations(\ReflectionClass $class): array
@@ -30,6 +32,7 @@ public function getClassAnnotations(\ReflectionClass $class): array
3032
}
3133

3234
/**
35+
* @phpstan-param \ReflectionClass<object> $class
3336
* @phpstan-param class-string $annotationName
3437
*
3538
* @return Annotation|Annotation[]|null
@@ -58,11 +61,12 @@ public function getPropertyAnnotation(\ReflectionProperty $property, string $ann
5861
}
5962

6063
/**
61-
* @param array<\ReflectionAttribute> $attributes
64+
* @param iterable<\ReflectionAttribute> $attributes
65+
* @phpstan-param iterable<\ReflectionAttribute<object>> $attributes
6266
*
6367
* @return array<string, Annotation|Annotation[]>
6468
*/
65-
private function convertToAttributeInstances(array $attributes): array
69+
private function convertToAttributeInstances(iterable $attributes): array
6670
{
6771
$instances = [];
6872

src/ReferenceIntegrity/ReferenceIntegrityListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Doctrine\Common\EventArgs;
1313
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
14+
use Doctrine\Persistence\Mapping\ClassMetadata;
15+
use Doctrine\Persistence\ObjectManager;
1416
use Gedmo\Exception\InvalidMappingException;
1517
use Gedmo\Exception\ReferenceIntegrityStrictException;
1618
use Gedmo\Mapping\MappedEventSubscriber;
@@ -40,6 +42,7 @@ public function getSubscribedEvents()
4042
* Maps additional metadata for the Document
4143
*
4244
* @param LoadClassMetadataEventArgs $eventArgs
45+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
4346
*
4447
* @return void
4548
*/

src/References/ReferencesListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\Common\Collections\ArrayCollection;
1313
use Doctrine\Common\EventArgs;
1414
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
15+
use Doctrine\Persistence\Mapping\ClassMetadata;
1516
use Doctrine\Persistence\ObjectManager;
1617
use Gedmo\Mapping\MappedEventSubscriber;
1718

@@ -61,6 +62,7 @@ public function __construct(array $managers = [])
6162

6263
/**
6364
* @param LoadClassMetadataEventArgs $eventArgs
65+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
6466
*
6567
* @return void
6668
*/

src/Sluggable/SluggableListener.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Doctrine\Common\EventArgs;
1313
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
14+
use Doctrine\Persistence\Mapping\ClassMetadata;
1415
use Doctrine\Persistence\ObjectManager;
1516
use Gedmo\Exception\InvalidArgumentException;
1617
use Gedmo\Mapping\MappedEventSubscriber;
@@ -225,6 +226,7 @@ public function removeManagedFilter($name)
225226
* Mapps additional metadata
226227
*
227228
* @param LoadClassMetadataEventArgs $eventArgs
229+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
228230
*
229231
* @return void
230232
*/

src/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Doctrine\ODM\MongoDB\UnitOfWork as MongoDBUnitOfWork;
1515
use Doctrine\ORM\EntityManagerInterface;
1616
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
17+
use Doctrine\Persistence\Mapping\ClassMetadata;
18+
use Doctrine\Persistence\ObjectManager;
1719
use Gedmo\Mapping\MappedEventSubscriber;
1820

1921
/**
@@ -108,6 +110,7 @@ public function onFlush(EventArgs $args)
108110
* Maps additional metadata
109111
*
110112
* @param LoadClassMetadataEventArgs $eventArgs
113+
* @phpstan-param LoadClassMetadataEventArgs<ClassMetadata<object>, ObjectManager> $eventArgs
111114
*
112115
* @return void
113116
*/

0 commit comments

Comments
 (0)