From 4c97daf6b16d6e759950a222bfc6133624bf99bf Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 6 Mar 2021 19:34:02 +0100 Subject: [PATCH] Fix level 6 of phpstan for util directory (#6905) --- src/Security/Handler/AclSecurityHandler.php | 6 +- .../Handler/AclSecurityHandlerInterface.php | 15 +++-- src/Util/AdminAclManipulatorInterface.php | 2 + src/Util/AdminAclUserManagerInterface.php | 4 ++ src/Util/AdminObjectAclData.php | 57 +++++++------------ src/Util/AdminObjectAclManipulator.php | 10 ++-- src/Util/FormBuilderIterator.php | 21 +++++-- src/Util/ObjectAclManipulator.php | 3 + src/Util/ObjectAclManipulatorInterface.php | 2 + src/Util/ParametersManipulator.php | 5 ++ 10 files changed, 70 insertions(+), 55 deletions(-) diff --git a/src/Security/Handler/AclSecurityHandler.php b/src/Security/Handler/AclSecurityHandler.php index 08d50bac11..0ab0647fbb 100644 --- a/src/Security/Handler/AclSecurityHandler.php +++ b/src/Security/Handler/AclSecurityHandler.php @@ -50,17 +50,17 @@ class AclSecurityHandler implements AclSecurityHandlerInterface protected $aclProvider; /** - * @var array + * @var string[] */ protected $superAdminRoles = []; /** - * @var array + * @var string[] */ protected $adminPermissions = []; /** - * @var array + * @var string[] */ protected $objectPermissions = []; diff --git a/src/Security/Handler/AclSecurityHandlerInterface.php b/src/Security/Handler/AclSecurityHandlerInterface.php index 8d69156b0a..da236e654e 100644 --- a/src/Security/Handler/AclSecurityHandlerInterface.php +++ b/src/Security/Handler/AclSecurityHandlerInterface.php @@ -17,6 +17,7 @@ use Symfony\Component\Security\Acl\Model\AclInterface; use Symfony\Component\Security\Acl\Model\MutableAclInterface; use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface; +use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; /** * @author Thomas Rabaix @@ -26,6 +27,8 @@ interface AclSecurityHandlerInterface extends SecurityHandlerInterface /** * Set the permissions not related to an object instance and also to be available when objects do not exist. * + * @param string[] $permissions + * * @return void */ public function setAdminPermissions(array $permissions); @@ -33,13 +36,15 @@ public function setAdminPermissions(array $permissions); /** * Return the permissions not related to an object instance and also to be available when objects do not exist. * - * @return array + * @return string[] */ public function getAdminPermissions(); /** * Set the permissions related to an object instance. * + * @param string[] $permissions + * * @return void */ public function setObjectPermissions(array $permissions); @@ -47,7 +52,7 @@ public function setObjectPermissions(array $permissions); /** * Return the permissions related to an object instance. * - * @return array + * @return string[] */ public function getObjectPermissions(); @@ -61,12 +66,12 @@ public function getObjectAcl(ObjectIdentityInterface $objectIdentity); /** * Find the ACLs for the passed object identities. * - * @param \Traversable $oids a collection of ObjectIdentityInterface implementations - * @param array $sids an array of SecurityIdentityInterface implementations + * @param \Traversable $oids + * @param SecurityIdentityInterface[] $sids * * @throws \Exception * - * @return \SplObjectStorage mapping the passed object identities to ACLs + * @return \SplObjectStorage mapping the passed object identities to ACLs */ public function findObjectAcls(\Traversable $oids, array $sids = []); diff --git a/src/Util/AdminAclManipulatorInterface.php b/src/Util/AdminAclManipulatorInterface.php index bcbebf17dd..abf4854ff5 100644 --- a/src/Util/AdminAclManipulatorInterface.php +++ b/src/Util/AdminAclManipulatorInterface.php @@ -26,6 +26,8 @@ interface AdminAclManipulatorInterface /** * Batch configure the ACLs for all objects handled by an Admin. * + * @param AdminInterface $admin + * * @return void */ public function configureAcls(OutputInterface $output, AdminInterface $admin); diff --git a/src/Util/AdminAclUserManagerInterface.php b/src/Util/AdminAclUserManagerInterface.php index 8bc57e3739..9b20972380 100644 --- a/src/Util/AdminAclUserManagerInterface.php +++ b/src/Util/AdminAclUserManagerInterface.php @@ -13,6 +13,8 @@ namespace Sonata\AdminBundle\Util; +use Symfony\Component\Security\Core\User\UserInterface; + /** * @author Mathieu Petrini */ @@ -20,6 +22,8 @@ interface AdminAclUserManagerInterface { /** * Batch configure the ACLs for all objects handled by an Admin. + * + * @return iterable */ public function findUsers(): iterable; } diff --git a/src/Util/AdminObjectAclData.php b/src/Util/AdminObjectAclData.php index ca2a80b78a..e981435f06 100644 --- a/src/Util/AdminObjectAclData.php +++ b/src/Util/AdminObjectAclData.php @@ -19,6 +19,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Security\Acl\Domain\Acl; use Symfony\Component\Security\Acl\Model\MutableAclInterface; +use Symfony\Component\Security\Core\User\UserInterface; /** * AdminObjectAclData holds data manipulated by {@link AdminObjectAclManipulator}. @@ -35,7 +36,7 @@ class AdminObjectAclData protected static $ownerPermissions = ['MASTER', 'OWNER']; /** - * @var AdminInterface + * @var AdminInterface */ protected $admin; @@ -45,12 +46,12 @@ class AdminObjectAclData protected $object; /** - * @var \Traversable Users to set ACL for + * @var \Traversable Users to set ACL for */ protected $aclUsers; /** - * @var \Traversable Roles to set ACL for + * @var \Traversable Roles to set ACL for */ protected $aclRoles; @@ -82,8 +83,11 @@ class AdminObjectAclData protected $maskBuilderClass; /** - * @param object $object - * @param string $maskBuilderClass + * @param AdminInterface $admin + * @param object $object + * @param string $maskBuilderClass + * @param \Traversable $aclUsers + * @param \Traversable|null $aclRoles * * @phpstan-param class-string $maskBuilderClass */ @@ -109,7 +113,7 @@ public function __construct( /** * Gets admin. * - * @return AdminInterface + * @return AdminInterface */ public function getAdmin() { @@ -127,9 +131,7 @@ public function getObject() } /** - * Gets ACL users. - * - * @return \Traversable + * @return \Traversable */ public function getAclUsers() { @@ -137,9 +139,7 @@ public function getAclUsers() } /** - * Gets ACL roles. - * - * @return \Traversable + * @return \Traversable */ public function getAclRoles() { @@ -147,8 +147,6 @@ public function getAclRoles() } /** - * Sets ACL. - * * @return AdminObjectAclData */ public function setAcl(MutableAclInterface $acl) @@ -159,8 +157,6 @@ public function setAcl(MutableAclInterface $acl) } /** - * Gets ACL. - * * @return MutableAclInterface|null */ public function getAcl() @@ -169,8 +165,6 @@ public function getAcl() } /** - * Gets masks. - * * @return array */ public function getMasks() @@ -179,8 +173,6 @@ public function getMasks() } /** - * Sets form. - * * NEXT_MAJOR: remove this method. * * @return AdminObjectAclData @@ -198,8 +190,6 @@ public function setForm(Form $form) } /** - * Gets form. - * * NEXT_MAJOR: remove this method. * * @return FormInterface @@ -217,8 +207,6 @@ public function getForm() } /** - * Sets ACL users form. - * * @return AdminObjectAclData */ public function setAclUsersForm(FormInterface $form) @@ -229,8 +217,6 @@ public function setAclUsersForm(FormInterface $form) } /** - * Gets ACL users form. - * * @return FormInterface|null */ public function getAclUsersForm() @@ -239,8 +225,6 @@ public function getAclUsersForm() } /** - * Sets ACL roles form. - * * @return AdminObjectAclData */ public function setAclRolesForm(FormInterface $form) @@ -251,8 +235,6 @@ public function setAclRolesForm(FormInterface $form) } /** - * Gets ACL roles form. - * * @return FormInterface|null */ public function getAclRolesForm() @@ -261,9 +243,7 @@ public function getAclRolesForm() } /** - * Gets permissions. - * - * @return array + * @return string[] */ public function getPermissions() { @@ -271,9 +251,7 @@ public function getPermissions() } /** - * Get permissions that the current user can set. - * - * @return array + * @return string[] */ public function getUserPermissions() { @@ -291,6 +269,9 @@ public function getUserPermissions() return $permissions; } + /** + * @return string[] + */ public function getOwnerPermissions() { return self::$ownerPermissions; @@ -308,8 +289,6 @@ public function isOwner() } /** - * Gets security handler. - * * @return AclSecurityHandlerInterface */ public function getSecurityHandler() @@ -330,6 +309,8 @@ public function getSecurityInformation() /** * Cache masks. + * + * @return void */ protected function updateMasks() { diff --git a/src/Util/AdminObjectAclManipulator.php b/src/Util/AdminObjectAclManipulator.php index 643eee1f23..34c2055ee7 100644 --- a/src/Util/AdminObjectAclManipulator.php +++ b/src/Util/AdminObjectAclManipulator.php @@ -121,7 +121,7 @@ public function createAclRolesForm(AdminObjectAclData $data) } /** - * Updates ACL users. + * @return void */ public function updateAclUsers(AdminObjectAclData $data) { @@ -132,7 +132,7 @@ public function updateAclUsers(AdminObjectAclData $data) } /** - * Updates ACL roles. + * @return void */ public function updateAclRoles(AdminObjectAclData $data) { @@ -143,11 +143,11 @@ public function updateAclRoles(AdminObjectAclData $data) } /** - * Updates ACl. - * * NEXT_MAJOR: remove this method. * * @deprecated since sonata-project/admin-bundle 3.0. Use updateAclUsers() instead + * + * @return void */ public function updateAcl(AdminObjectAclData $data) { @@ -162,6 +162,8 @@ public function updateAcl(AdminObjectAclData $data) /** * @param \Traversable $aclValues * + * @return void + * * @phpstan-param \Traversable $aclValues */ protected function buildAcl(AdminObjectAclData $data, FormInterface $form, \Traversable $aclValues) diff --git a/src/Util/FormBuilderIterator.php b/src/Util/FormBuilderIterator.php index 186e4d63b3..df039a0a0d 100644 --- a/src/Util/FormBuilderIterator.php +++ b/src/Util/FormBuilderIterator.php @@ -33,7 +33,11 @@ class FormBuilderIterator extends \RecursiveArrayIterator protected $formBuilder; /** - * @var array + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/sonata-admin-bundle 3.x + * + * @var mixed[] */ protected $keys = []; @@ -43,7 +47,7 @@ class FormBuilderIterator extends \RecursiveArrayIterator protected $prefix; /** - * @var \ArrayIterator + * @var \ArrayIterator */ protected $iterator; @@ -83,6 +87,9 @@ public function valid() return $this->iterator->valid(); } + /** + * @return string + */ public function key() { $name = $this->iterator->current(); @@ -95,11 +102,17 @@ public function next() $this->iterator->next(); } + /** + * @return FormBuilderInterface + */ public function current() { return $this->formBuilder->get($this->iterator->current()); } + /** + * @return FormBuilderIterator + */ public function getChildren() { return new self($this->formBuilder->get($this->iterator->current()), $this->key()); @@ -111,9 +124,7 @@ public function hasChildren() } /** - * @return array - * - * @phpstan-return array-key[] + * @return array */ private static function getKeys(FormBuilderInterface $formBuilder) { diff --git a/src/Util/ObjectAclManipulator.php b/src/Util/ObjectAclManipulator.php index fee2048432..9f5ac39d2d 100644 --- a/src/Util/ObjectAclManipulator.php +++ b/src/Util/ObjectAclManipulator.php @@ -26,6 +26,9 @@ abstract class ObjectAclManipulator implements ObjectAclManipulatorInterface /** * Configure the object ACL for the passed object identities. * + * @param AdminInterface $admin + * @param \Traversable $oids + * * @throws \Exception * * @return array [countAdded, countUpdated] diff --git a/src/Util/ObjectAclManipulatorInterface.php b/src/Util/ObjectAclManipulatorInterface.php index 5d349a05de..de992a26fb 100644 --- a/src/Util/ObjectAclManipulatorInterface.php +++ b/src/Util/ObjectAclManipulatorInterface.php @@ -26,6 +26,8 @@ interface ObjectAclManipulatorInterface /** * Batch configure the ACLs for all objects handled by an Admin. * + * @param AdminInterface $admin + * * @throws ModelManagerException * * @return void diff --git a/src/Util/ParametersManipulator.php b/src/Util/ParametersManipulator.php index 06712712cb..cca331e11e 100644 --- a/src/Util/ParametersManipulator.php +++ b/src/Util/ParametersManipulator.php @@ -20,6 +20,11 @@ final class ParametersManipulator { /** * Merge parameters, but replace them when it's a subarray. + * + * @param mixed[] $parameters + * @param mixed[] $newParameters + * + * @return mixed[] */ public static function merge(array $parameters, array $newParameters): array {