Skip to content

Commit

Permalink
Add generics for the event subscriber configuration arrays and adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Aug 18, 2024
1 parent bc33f35 commit b44e39b
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 59 deletions.
20 changes: 0 additions & 20 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -285,21 +285,6 @@ parameters:
count: 1
path: src/References/ReferencesListener.php

-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:extractIdentifier\\(\\)\\.$#"
count: 2
path: src/References/ReferencesListener.php

-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getIdentifier\\(\\)\\.$#"
count: 1
path: src/References/ReferencesListener.php

-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getSingleReference\\(\\)\\.$#"
count: 1
path: src/References/ReferencesListener.php

-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:getReflectionProperty\\(\\)\\.$#"
count: 2
Expand Down Expand Up @@ -400,11 +385,6 @@ parameters:
count: 1
path: src/SoftDeleteable/Query/TreeWalker/SoftDeleteableWalker.php

-
message: "#^Call to an undefined method Gedmo\\\\Mapping\\\\Event\\\\AdapterInterface\\:\\:getDateValue\\(\\)\\.$#"
count: 1
path: src/SoftDeleteable/SoftDeleteableListener.php

-
message: "#^Access to offset 'inherited' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\AssociationFieldMapping\\.$#"
count: 1
Expand Down
5 changes: 5 additions & 0 deletions src/AbstractTrackingListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
/**
* The AbstractTrackingListener provides generic functions for all listeners.
*
* @phpstan-template TConfig of array
* @phpstan-template TEventAdapter of AdapterInterface
*
* @phpstan-extends MappedEventSubscriber<TConfig, TEventAdapter>
*
* @author Gediminas Morkevicius <[email protected]>
*/
abstract class AbstractTrackingListener extends MappedEventSubscriber
Expand Down
3 changes: 3 additions & 0 deletions src/Blameable/BlameableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@

use Doctrine\Persistence\Mapping\ClassMetadata;
use Gedmo\AbstractTrackingListener;
use Gedmo\Blameable\Mapping\Event\BlameableAdapter;
use Gedmo\Exception\InvalidArgumentException;

/**
* The Blameable listener handles the update of
* dates on creation and update.
*
* @phpstan-extends AbstractTrackingListener<array, BlameableAdapter>
*
* @author Gediminas Morkevicius <[email protected]>
*
* @final since gedmo/doctrine-extensions 3.11
Expand Down
3 changes: 3 additions & 0 deletions src/IpTraceable/IpTraceableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
use Doctrine\Persistence\Mapping\ClassMetadata;
use Gedmo\AbstractTrackingListener;
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\IpTraceable\Mapping\Event\IpTraceableAdapter;
use Gedmo\Mapping\Event\AdapterInterface;

/**
* The IpTraceable listener handles the update of
* IPs on creation and update.
*
* @phpstan-extends AbstractTrackingListener<array, IpTraceableAdapter>
*
* @author Pierre-Charles Bertineau <[email protected]>
*
* @final since gedmo/doctrine-extensions 3.11
Expand Down
7 changes: 2 additions & 5 deletions src/Loggable/LoggableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Exception\InvalidArgumentException;
use Gedmo\Loggable\Entity\LogEntry;
use Gedmo\Loggable\Mapping\Event\LoggableAdapter;
use Gedmo\Mapping\MappedEventSubscriber;
use Gedmo\Tool\Wrapper\AbstractWrapper;
Expand All @@ -35,11 +34,9 @@
* versioned?: string[],
* }
*
* @phpstan-method LoggableConfiguration getConfiguration(ObjectManager $objectManager, $class)
*
* @method LoggableAdapter getEventAdapter(EventArgs $args)
*
* @phpstan-template T of Loggable|object
*
* @phpstan-extends MappedEventSubscriber<LoggableConfiguration, LoggableAdapter>
*/
class LoggableListener extends MappedEventSubscriber
{
Expand Down
27 changes: 6 additions & 21 deletions src/Mapping/MappedEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
use Gedmo\Mapping\Driver\AttributeReader;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Mapping\Event\ClockAwareAdapterInterface;
use Gedmo\ReferenceIntegrity\Mapping\Validator as ReferenceIntegrityValidator;
use Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface;
use Gedmo\Uploadable\Mapping\Validator as MappingValidator;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Clock\ClockInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
Expand All @@ -43,6 +40,9 @@
* all extensions who maps additional metadata through
* extended drivers
*
* @phpstan-template TConfig of array
* @phpstan-template TEventAdapter of AdapterInterface
*
* @author Gediminas Morkevicius <[email protected]>
*/
abstract class MappedEventSubscriber implements EventSubscriber
Expand Down Expand Up @@ -115,24 +115,7 @@ public function __construct()
*
* @return array<string, mixed>
*
* @phpstan-return array{
* useObjectClass?: class-string,
* referenceIntegrity?: array<string, array<string, value-of<ReferenceIntegrityValidator::INTEGRITY_ACTIONS>>>,
* filePathField?: string,
* uploadable?: bool,
* fileNameField?: string,
* allowOverwrite?: bool,
* appendNumber?: bool,
* maxSize?: float,
* path?: string,
* pathMethod?: string,
* allowedTypes?: string[],
* disallowedTypes?: string[],
* filenameGenerator?: MappingValidator::FILENAME_GENERATOR_*|class-string<FilenameGeneratorInterface>,
* fileMimeTypeField?: string,
* fileSizeField?: string,
* callback?: string,
* }
* @phpstan-return TConfig
*/
public function getConfiguration(ObjectManager $objectManager, $class)
{
Expand Down Expand Up @@ -273,6 +256,8 @@ public function loadMetadataForObjectClass(ObjectManager $objectManager, $metada
* @throws InvalidArgumentException if event is not recognized
*
* @return AdapterInterface
*
* @phpstan-return TEventAdapter
*/
protected function getEventAdapter(EventArgs $args)
{
Expand Down
3 changes: 3 additions & 0 deletions src/ReferenceIntegrity/ReferenceIntegrityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
use Doctrine\Persistence\ObjectManager;
use Gedmo\Exception\InvalidMappingException;
use Gedmo\Exception\ReferenceIntegrityStrictException;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Mapping\MappedEventSubscriber;
use Gedmo\ReferenceIntegrity\Mapping\Validator;

/**
* The ReferenceIntegrity listener handles the reference integrity on related documents
*
* @phpstan-extends MappedEventSubscriber<array, AdapterInterface>
*
* @author Evert Harmeling <[email protected]>
*
* @final since gedmo/doctrine-extensions 3.11
Expand Down
3 changes: 2 additions & 1 deletion src/References/ReferencesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Mapping\MappedEventSubscriber;
use Gedmo\References\Mapping\Event\ReferencesAdapter;

/**
* Listener for loading and persisting cross database references.
Expand All @@ -39,7 +40,7 @@
* useObjectClass?: class-string,
* }
*
* @phpstan-method ReferencesConfiguration getConfiguration(ObjectManager $objectManager, $class)
* @phpstan-extends MappedEventSubscriber<ReferencesConfiguration, ReferencesAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Sluggable/SluggableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@
* useObjectClass?: class-string,
* }
*
* @phpstan-method SluggableConfiguration getConfiguration(ObjectManager $objectManager, $class)
*
* @method SluggableAdapter getEventAdapter(EventArgs $args)
* @phpstan-extends MappedEventSubscriber<SluggableConfiguration, SluggableAdapter>
*/
class SluggableListener extends MappedEventSubscriber
{
Expand Down
3 changes: 3 additions & 0 deletions src/SoftDeleteable/SoftDeleteableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
use Gedmo\Mapping\MappedEventSubscriber;
use Gedmo\SoftDeleteable\Event\PostSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Event\PreSoftDeleteEventArgs;
use Gedmo\SoftDeleteable\Mapping\Event\SoftDeleteableAdapter;

/**
* SoftDeleteable listener
*
* @phpstan-extends MappedEventSubscriber<array, SoftDeleteableAdapter>
*
* @author Gustavo Falco <[email protected]>
* @author Gediminas Morkevicius <[email protected]>
*
Expand Down
4 changes: 1 addition & 3 deletions src/Sortable/SortableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
* }>,
* }
*
* @phpstan-method SortableConfiguration getConfiguration(ObjectManager $objectManager, $class)
*
* @method SortableAdapter getEventAdapter(EventArgs $args)
* @phpstan-extends MappedEventSubscriber<SortableConfiguration, SortableAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Timestampable/TimestampableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
* @author Gediminas Morkevicius <[email protected]>
*
* @phpstan-extends AbstractTrackingListener<array, TimestampableAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
class TimestampableListener extends AbstractTrackingListener
Expand Down
4 changes: 1 addition & 3 deletions src/Translatable/TranslatableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
* useObjectClass?: class-string,
* }
*
* @phpstan-method TranslatableConfiguration getConfiguration(ObjectManager $objectManager, $class)
*
* @method TranslatableAdapter getEventAdapter(EventArgs $args)
* @phpstan-extends MappedEventSubscriber<TranslatableConfiguration, TranslatableAdapter>
*
* @final since gedmo/doctrine-extensions 3.11
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Tree/TreeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@
* level_base?: int,
* }
*
* @phpstan-method TreeConfiguration getConfiguration(ObjectManager $objectManager, $class)
*
* @method TreeAdapter getEventAdapter(EventArgs $args)
* @phpstan-extends MappedEventSubscriber<TreeConfiguration, TreeAdapter>
*/
class TreeListener extends MappedEventSubscriber
{
Expand Down
20 changes: 20 additions & 0 deletions src/Uploadable/UploadableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Gedmo\Uploadable\Event\UploadablePreFileProcessEventArgs;
use Gedmo\Uploadable\FileInfo\FileInfoArray;
use Gedmo\Uploadable\FileInfo\FileInfoInterface;
use Gedmo\Uploadable\FilenameGenerator\FilenameGeneratorInterface;
use Gedmo\Uploadable\Mapping\Validator;
use Gedmo\Uploadable\MimeType\MimeTypeGuesser;
use Gedmo\Uploadable\MimeType\MimeTypeGuesserInterface;
Expand All @@ -46,6 +47,25 @@
*
* @author Gustavo Falco <[email protected]>
* @author Gediminas Morkevicius <[email protected]>
*
* @phpstan-type UploadableConfiguration = array{
* filePathField?: string,
* uploadable?: bool,
* fileNameField?: string,
* allowOverwrite?: bool,
* appendNumber?: bool,
* maxSize?: float,
* path?: string,
* pathMethod?: string,
* allowedTypes?: string[],
* disallowedTypes?: string[],
* filenameGenerator?: Validator::FILENAME_GENERATOR_*|class-string<FilenameGeneratorInterface>,
* fileMimeTypeField?: string,
* fileSizeField?: string,
* callback?: string,
* }
*
* @phpstan-extends MappedEventSubscriber<UploadableConfiguration, AdapterInterface>
*/
class UploadableListener extends MappedEventSubscriber
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Gedmo/Mapping/Mock/EventSubscriberCustomMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Mapping\MappedEventSubscriber;

/**
* @phpstan-extends MappedEventSubscriber<array, AdapterInterface>
*/
final class EventSubscriberCustomMock extends MappedEventSubscriber
{
public function getAdapter(EventArgs $args): AdapterInterface
Expand Down
3 changes: 3 additions & 0 deletions tests/Gedmo/Mapping/Mock/EventSubscriberMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Mapping\MappedEventSubscriber;

/**
* @phpstan-extends MappedEventSubscriber<array, AdapterInterface>
*/
final class EventSubscriberMock extends MappedEventSubscriber
{
public function getAdapter(EventArgs $args): AdapterInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
use Doctrine\Persistence\Event\LoadClassMetadataEventArgs;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Gedmo\Mapping\Event\AdapterInterface;
use Gedmo\Mapping\Event\AdapterInterface as EventAdapterInterface;
use Gedmo\Mapping\MappedEventSubscriber;

/**
* @phpstan-extends MappedEventSubscriber<array, AdapterInterface>
*/
class EncoderListener extends MappedEventSubscriber
{
public function getSubscribedEvents(): array
Expand Down
3 changes: 3 additions & 0 deletions tests/Gedmo/Timestampable/ChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ public function getDateValue($meta, $field): ?\DateTime
}
}

/**
* @phpstan-extends AbstractTrackingListener<array, TimestampableAdapter>
*/
final class TimestampableListenerStub extends AbstractTrackingListener
{
/**
Expand Down

0 comments on commit b44e39b

Please sign in to comment.