From 82121f72131547ab83dc895790a66dc096b3fc9c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 14 Apr 2021 23:47:09 +0200 Subject: [PATCH] Move template param to the class --- src/Admin/AdminInterface.php | 1 + .../Admin/AbstractTaggedAdmin.php | 5 +++++ .../Admin/TaggedAdminInterface.php | 5 +++++ src/Form/DataTransformer/ArrayToModelTransformer.php | 4 +++- .../DataTransformer/ModelToIdPropertyTransformer.php | 4 +++- src/Form/DataTransformer/ModelToIdTransformer.php | 4 +++- .../DataTransformer/ModelsToArrayTransformer.php | 4 +++- src/Model/ModelManagerInterface.php | 12 ++++-------- 8 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index a57b2c0e12..92d026b7b4 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -58,6 +58,7 @@ * @phpstan-extends AccessRegistryInterface * @phpstan-extends UrlGeneratorInterface * @phpstan-extends LifecycleHookProviderInterface + * @phpstan-extends TaggedAdminInterface */ interface AdminInterface extends TaggedAdminInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface { diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index 8bec4b8611..742d36a55f 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -33,6 +33,7 @@ /** * @phpstan-template T of object + * @phpstan-implements TaggedAdminInterface */ abstract class AbstractTaggedAdmin implements TaggedAdminInterface { @@ -117,6 +118,7 @@ abstract class AbstractTaggedAdmin implements TaggedAdminInterface * The Entity or Document manager. * * @var ModelManagerInterface|null + * @phpstan-var ModelManagerInterface|null */ protected $modelManager; @@ -372,7 +374,10 @@ final public function hasFilterPersister(): bool } /** + * NEXT_MAJOR: Move the phpdoc to the interface. + * * @final since sonata-admin/admin-bundle 3.84 + * @phpstan-param ModelManagerInterface $modelManager */ public function setModelManager(ModelManagerInterface $modelManager) { diff --git a/src/DependencyInjection/Admin/TaggedAdminInterface.php b/src/DependencyInjection/Admin/TaggedAdminInterface.php index 4043865a36..2e99bb4a25 100644 --- a/src/DependencyInjection/Admin/TaggedAdminInterface.php +++ b/src/DependencyInjection/Admin/TaggedAdminInterface.php @@ -63,6 +63,8 @@ * @method Pool getConfigurationPool() * @method void setRouteGenerator(RouteGeneratorInterface $routeGenerator) * @method RouteGeneratorInterface getRouteGenerator() + * + * @phpstan-template T of object */ interface TaggedAdminInterface { @@ -153,11 +155,14 @@ public function getSecurityInformation(); /** * NEXT_MAJOR: Uncomment this method. + * + * @phpstan-param ModelManagerInterface */ // public function setModelManager(ModelManagerInterface $modelManager): void; /** * @return ModelManagerInterface + * @phpstan-return ModelManagerInterface */ public function getModelManager(); diff --git a/src/Form/DataTransformer/ArrayToModelTransformer.php b/src/Form/DataTransformer/ArrayToModelTransformer.php index 5940832185..94771ea6ae 100644 --- a/src/Form/DataTransformer/ArrayToModelTransformer.php +++ b/src/Form/DataTransformer/ArrayToModelTransformer.php @@ -28,6 +28,7 @@ class ArrayToModelTransformer implements DataTransformerInterface { /** * @var ModelManagerInterface + * @phpstan-var ModelManagerInterface */ protected $modelManager; @@ -41,7 +42,8 @@ class ArrayToModelTransformer implements DataTransformerInterface /** * @param string $className * - * @phpstan-param class-string $className + * @phpstan-param ModelManagerInterface $modelManager + * @phpstan-param class-string $className */ public function __construct(ModelManagerInterface $modelManager, $className) { diff --git a/src/Form/DataTransformer/ModelToIdPropertyTransformer.php b/src/Form/DataTransformer/ModelToIdPropertyTransformer.php index 1df34d1850..ee1950ec0b 100644 --- a/src/Form/DataTransformer/ModelToIdPropertyTransformer.php +++ b/src/Form/DataTransformer/ModelToIdPropertyTransformer.php @@ -33,6 +33,7 @@ class ModelToIdPropertyTransformer implements DataTransformerInterface { /** * @var ModelManagerInterface + * @phpstan-var ModelManagerInterface */ protected $modelManager; @@ -65,7 +66,8 @@ class ModelToIdPropertyTransformer implements DataTransformerInterface * @param callable|null $toStringCallback * * @phpstan-template P - * @phpstan-param class-string $className + * @phpstan-param ModelManagerInterface $modelManager + * @phpstan-param class-string $className * @phpstan-param null|callable(object, P): string $toStringCallback */ public function __construct( diff --git a/src/Form/DataTransformer/ModelToIdTransformer.php b/src/Form/DataTransformer/ModelToIdTransformer.php index b43655252a..13cdcfd7fd 100644 --- a/src/Form/DataTransformer/ModelToIdTransformer.php +++ b/src/Form/DataTransformer/ModelToIdTransformer.php @@ -27,6 +27,7 @@ class ModelToIdTransformer implements DataTransformerInterface { /** * @var ModelManagerInterface + * @phpstan-var ModelManagerInterface */ protected $modelManager; @@ -40,7 +41,8 @@ class ModelToIdTransformer implements DataTransformerInterface /** * @param string $className * - * @phpstan-param class-string $className + * @phpstan-param ModelManagerInterface $modelManager + * @phpstan-param class-string $className */ public function __construct(ModelManagerInterface $modelManager, $className) { diff --git a/src/Form/DataTransformer/ModelsToArrayTransformer.php b/src/Form/DataTransformer/ModelsToArrayTransformer.php index 1e7ea9ec41..2fec73d792 100644 --- a/src/Form/DataTransformer/ModelsToArrayTransformer.php +++ b/src/Form/DataTransformer/ModelsToArrayTransformer.php @@ -37,6 +37,7 @@ class ModelsToArrayTransformer implements DataTransformerInterface { /** * @var ModelManagerInterface + * @phpstan-var ModelManagerInterface */ protected $modelManager; @@ -60,7 +61,8 @@ class ModelsToArrayTransformer implements DataTransformerInterface * @param ModelManagerInterface $modelManager * @param string $class * - * @phpstan-param class-string $class + * @phpstan-param ModelManagerInterface $modelManager + * @phpstan-param class-string $class * * @throws RuntimeException */ diff --git a/src/Model/ModelManagerInterface.php b/src/Model/ModelManagerInterface.php index b2dcd2ab2b..72361cae79 100644 --- a/src/Model/ModelManagerInterface.php +++ b/src/Model/ModelManagerInterface.php @@ -28,6 +28,8 @@ * * @method bool supportsQuery(object $query) * @method void reverseTransform(object $object, array $array = []) + * + * @phpstan-template T of object */ interface ModelManagerInterface extends DatagridManagerInterface { @@ -72,7 +74,6 @@ public function delete($object); * * @return object[] all objects matching the criteria * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T[] */ @@ -84,7 +85,6 @@ public function findBy($class, array $criteria = []); * * @return object|null an object matching the criteria or null if none match * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T|null */ @@ -96,7 +96,6 @@ public function findOneBy($class, array $criteria = []); * * @return object|null the object with id or null if not found * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T|null */ @@ -204,7 +203,6 @@ public function getUrlSafeIdentifier($model); * * @return object * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T */ @@ -291,7 +289,6 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D * * @return object * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T */ @@ -310,7 +307,6 @@ public function modelReverseTransform($class, array $array = []); * * @return object * - * @phpstan-template T of object * @phpstan-param class-string $class * @phpstan-return T */ @@ -346,7 +342,7 @@ public function getDataSourceIterator( * * @return string[] * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ public function getExportFields($class); @@ -366,7 +362,7 @@ public function getPaginationParameters(DatagridInterface $datagrid, $page); * @param string $class * @param array $idx * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ public function addIdentifiersToQuery($class, ProxyQueryInterface $query, array $idx); }