From fcd78d5b40428e5e7bb1ce2e5078e29741b65c55 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Apr 2021 12:38:40 +0200 Subject: [PATCH 1/6] Restrict datagridBuilder type to class-string --- src/Builder/DatagridBuilderInterface.php | 2 ++ src/Builder/FormContractorInterface.php | 3 +++ src/Datagrid/DatagridMapper.php | 2 ++ 3 files changed, 7 insertions(+) diff --git a/src/Builder/DatagridBuilderInterface.php b/src/Builder/DatagridBuilderInterface.php index 76ac3aa6c5..8469934c4a 100644 --- a/src/Builder/DatagridBuilderInterface.php +++ b/src/Builder/DatagridBuilderInterface.php @@ -25,6 +25,8 @@ interface DatagridBuilderInterface extends BuilderInterface /** * @param string|null $type * @param AdminInterface $admin + * + * @phpstan-param class-string $type */ public function addFilter( DatagridInterface $datagrid, diff --git a/src/Builder/FormContractorInterface.php b/src/Builder/FormContractorInterface.php index 081c83ddff..b5deaccf00 100644 --- a/src/Builder/FormContractorInterface.php +++ b/src/Builder/FormContractorInterface.php @@ -24,6 +24,9 @@ */ interface FormContractorInterface extends BuilderInterface { + /** + * NEXT_MAJOR: Remove the __construct from the interface. + */ public function __construct(FormFactoryInterface $formFactory); /** diff --git a/src/Datagrid/DatagridMapper.php b/src/Datagrid/DatagridMapper.php index 66b64efb40..06f7f4c8a6 100644 --- a/src/Datagrid/DatagridMapper.php +++ b/src/Datagrid/DatagridMapper.php @@ -74,6 +74,8 @@ public function getAdmin() * @throws \LogicException * * @return DatagridMapper + * + * @phpstan-param class-string|null $type */ public function add( $name, From f8faa0ca6849e6fd501a8f80a25a745f40da9541 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Apr 2021 13:05:27 +0200 Subject: [PATCH 2/6] Add template for DatagridBuilderInterface --- src/Builder/DatagridBuilderInterface.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Builder/DatagridBuilderInterface.php b/src/Builder/DatagridBuilderInterface.php index 8469934c4a..8d81015069 100644 --- a/src/Builder/DatagridBuilderInterface.php +++ b/src/Builder/DatagridBuilderInterface.php @@ -15,10 +15,13 @@ use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; +use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface; /** * @author Thomas Rabaix + * + * @phpstan-template T of \Sonata\AdminBundle\Datagrid\ProxyQueryInterface */ interface DatagridBuilderInterface extends BuilderInterface { @@ -26,7 +29,8 @@ interface DatagridBuilderInterface extends BuilderInterface * @param string|null $type * @param AdminInterface $admin * - * @phpstan-param class-string $type + * @phpstan-param DatagridInterface $datagrid + * @phpstan-param class-string $type */ public function addFilter( DatagridInterface $datagrid, @@ -40,6 +44,8 @@ public function addFilter( * @param array $values * * @return DatagridInterface + * + * @phpstan-return DatagridInterface */ public function getBaseDatagrid(AdminInterface $admin, array $values = []); } From d354761bc6ef5b93eff1e3011f55fc9f34a64103 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Apr 2021 13:17:59 +0200 Subject: [PATCH 3/6] Add missing generic for ModelManagerInterface --- src/Model/ModelManagerInterface.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Model/ModelManagerInterface.php b/src/Model/ModelManagerInterface.php index 1db1fb3b5d..109c052a15 100644 --- a/src/Model/ModelManagerInterface.php +++ b/src/Model/ModelManagerInterface.php @@ -51,6 +51,8 @@ public function getNewFieldDescriptionInstance($class, $name, array $options = [ * @param object $object * * @throws ModelManagerException + * + * @phpstan-param T $object */ public function create($object); @@ -58,6 +60,8 @@ public function create($object); * @param object $object * * @throws ModelManagerException + * + * @phpstan-param T $object */ public function update($object); @@ -65,6 +69,8 @@ public function update($object); * @param object $object * * @throws ModelManagerException + * + * @phpstan-param T $object */ public function delete($object); @@ -106,7 +112,7 @@ public function find($class, $id); * * @throws ModelManagerException * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ public function batchDelete($class, ProxyQueryInterface $query); @@ -128,7 +134,7 @@ public function getParentFieldDescription($parentAssociationMapping, $class); * * @return ProxyQueryInterface * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ public function createQuery($class); @@ -157,6 +163,8 @@ public function getModelIdentifier($class); * @param object $model * * @return array list of all identifiers of this model + * + * @phpstan-param T $model */ public function getIdentifierValues($model); @@ -168,7 +176,7 @@ public function getIdentifierValues($model); * * @return string[] * - * @phpstan-param class-string $class + * @phpstan-param class-string $class */ public function getIdentifierFieldNames($class); @@ -179,6 +187,8 @@ public function getIdentifierFieldNames($class); * * @return string|null a string representation of the identifiers for this * instance + * + * @phpstan-param T $model */ public function getNormalizedIdentifier($model); @@ -191,6 +201,8 @@ public function getNormalizedIdentifier($model); * @param object $model * * @return string|null string representation of the id that is safe to use in a url + * + * @phpstan-param T $model */ public function getUrlSafeIdentifier($model); @@ -295,6 +307,9 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D public function modelReverseTransform($class, array $array = []); // NEXT_MAJOR: Uncomment this. + /** + * @phpstan-param T $object + */ // public function reverseTransform(object $object, array $array = []): void; /** From e9e2601768917b721ece5f4d627eaecf5c2a72f6 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Apr 2021 13:19:30 +0200 Subject: [PATCH 4/6] Add generic to LockInterface --- src/Model/LockInterface.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Model/LockInterface.php b/src/Model/LockInterface.php index 9641e61403..2e14ff3928 100644 --- a/src/Model/LockInterface.php +++ b/src/Model/LockInterface.php @@ -17,6 +17,8 @@ /** * @author Emmanuel Vella + * + * @phpstan-template T of object */ interface LockInterface { @@ -24,6 +26,8 @@ interface LockInterface * @param object $object * * @return mixed|null + * + * @phpstan-param T $object */ public function getLockVersion($object); @@ -32,6 +36,8 @@ public function getLockVersion($object); * @param mixed $expectedVersion * * @throws LockException + * + * @phpstan-param T $object */ public function lock($object, $expectedVersion); } From 8e016e22a3e9f070aa6c6e79e41692a9436d0bac Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 19 Apr 2021 13:22:33 +0200 Subject: [PATCH 5/6] Fix lint --- src/Builder/DatagridBuilderInterface.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Builder/DatagridBuilderInterface.php b/src/Builder/DatagridBuilderInterface.php index 8d81015069..eeaf6d5dd2 100644 --- a/src/Builder/DatagridBuilderInterface.php +++ b/src/Builder/DatagridBuilderInterface.php @@ -15,7 +15,6 @@ use Sonata\AdminBundle\Admin\AdminInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; -use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\FieldDescription\FieldDescriptionInterface; /** From 0fe7b3acefcb6fb796530c68282f8853e620240c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 27 Apr 2021 00:59:05 +0200 Subject: [PATCH 6/6] Update src/Builder/FormContractorInterface.php Co-authored-by: Javier Spagnoletti --- src/Builder/FormContractorInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Builder/FormContractorInterface.php b/src/Builder/FormContractorInterface.php index b5deaccf00..995b2c0595 100644 --- a/src/Builder/FormContractorInterface.php +++ b/src/Builder/FormContractorInterface.php @@ -25,7 +25,7 @@ interface FormContractorInterface extends BuilderInterface { /** - * NEXT_MAJOR: Remove the __construct from the interface. + * NEXT_MAJOR: Remove the `__construct()` method from the interface. */ public function __construct(FormFactoryInterface $formFactory);