Skip to content

Commit

Permalink
Fix level 6 of phpstan for util directory (#6905)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Mar 6, 2021
1 parent 6cfa7e5 commit 4c97daf
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 55 deletions.
6 changes: 3 additions & 3 deletions src/Security/Handler/AclSecurityHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
15 changes: 10 additions & 5 deletions src/Security/Handler/AclSecurityHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand All @@ -26,28 +27,32 @@ 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);

/**
* 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);

/**
* Return the permissions related to an object instance.
*
* @return array
* @return string[]
*/
public function getObjectPermissions();

Expand All @@ -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<ObjectIdentityInterface> $oids
* @param SecurityIdentityInterface[] $sids
*
* @throws \Exception
*
* @return \SplObjectStorage mapping the passed object identities to ACLs
* @return \SplObjectStorage<ObjectIdentityInterface, SecurityIdentityInterface> mapping the passed object identities to ACLs
*/
public function findObjectAcls(\Traversable $oids, array $sids = []);

Expand Down
2 changes: 2 additions & 0 deletions src/Util/AdminAclManipulatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface AdminAclManipulatorInterface
/**
* Batch configure the ACLs for all objects handled by an Admin.
*
* @param AdminInterface<object> $admin
*
* @return void
*/
public function configureAcls(OutputInterface $output, AdminInterface $admin);
Expand Down
4 changes: 4 additions & 0 deletions src/Util/AdminAclUserManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@

namespace Sonata\AdminBundle\Util;

use Symfony\Component\Security\Core\User\UserInterface;

/**
* @author Mathieu Petrini <[email protected]>
*/
interface AdminAclUserManagerInterface
{
/**
* Batch configure the ACLs for all objects handled by an Admin.
*
* @return iterable<UserInterface|string>
*/
public function findUsers(): iterable;
}
57 changes: 19 additions & 38 deletions src/Util/AdminObjectAclData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -35,7 +36,7 @@ class AdminObjectAclData
protected static $ownerPermissions = ['MASTER', 'OWNER'];

/**
* @var AdminInterface
* @var AdminInterface<object>
*/
protected $admin;

Expand All @@ -45,12 +46,12 @@ class AdminObjectAclData
protected $object;

/**
* @var \Traversable Users to set ACL for
* @var \Traversable<UserInterface|string> Users to set ACL for
*/
protected $aclUsers;

/**
* @var \Traversable Roles to set ACL for
* @var \Traversable<string> Roles to set ACL for
*/
protected $aclRoles;

Expand Down Expand Up @@ -82,8 +83,11 @@ class AdminObjectAclData
protected $maskBuilderClass;

/**
* @param object $object
* @param string $maskBuilderClass
* @param AdminInterface<object> $admin
* @param object $object
* @param string $maskBuilderClass
* @param \Traversable<UserInterface|string> $aclUsers
* @param \Traversable<string>|null $aclRoles
*
* @phpstan-param class-string $maskBuilderClass
*/
Expand All @@ -109,7 +113,7 @@ public function __construct(
/**
* Gets admin.
*
* @return AdminInterface
* @return AdminInterface<object>
*/
public function getAdmin()
{
Expand All @@ -127,28 +131,22 @@ public function getObject()
}

/**
* Gets ACL users.
*
* @return \Traversable
* @return \Traversable<UserInterface|string>
*/
public function getAclUsers()
{
return $this->aclUsers;
}

/**
* Gets ACL roles.
*
* @return \Traversable
* @return \Traversable<string>
*/
public function getAclRoles()
{
return $this->aclRoles;
}

/**
* Sets ACL.
*
* @return AdminObjectAclData
*/
public function setAcl(MutableAclInterface $acl)
Expand All @@ -159,8 +157,6 @@ public function setAcl(MutableAclInterface $acl)
}

/**
* Gets ACL.
*
* @return MutableAclInterface|null
*/
public function getAcl()
Expand All @@ -169,8 +165,6 @@ public function getAcl()
}

/**
* Gets masks.
*
* @return array<string, mixed>
*/
public function getMasks()
Expand All @@ -179,8 +173,6 @@ public function getMasks()
}

/**
* Sets form.
*
* NEXT_MAJOR: remove this method.
*
* @return AdminObjectAclData
Expand All @@ -198,8 +190,6 @@ public function setForm(Form $form)
}

/**
* Gets form.
*
* NEXT_MAJOR: remove this method.
*
* @return FormInterface
Expand All @@ -217,8 +207,6 @@ public function getForm()
}

/**
* Sets ACL users form.
*
* @return AdminObjectAclData
*/
public function setAclUsersForm(FormInterface $form)
Expand All @@ -229,8 +217,6 @@ public function setAclUsersForm(FormInterface $form)
}

/**
* Gets ACL users form.
*
* @return FormInterface|null
*/
public function getAclUsersForm()
Expand All @@ -239,8 +225,6 @@ public function getAclUsersForm()
}

/**
* Sets ACL roles form.
*
* @return AdminObjectAclData
*/
public function setAclRolesForm(FormInterface $form)
Expand All @@ -251,8 +235,6 @@ public function setAclRolesForm(FormInterface $form)
}

/**
* Gets ACL roles form.
*
* @return FormInterface|null
*/
public function getAclRolesForm()
Expand All @@ -261,19 +243,15 @@ public function getAclRolesForm()
}

/**
* Gets permissions.
*
* @return array
* @return string[]
*/
public function getPermissions()
{
return $this->getSecurityHandler()->getObjectPermissions();
}

/**
* Get permissions that the current user can set.
*
* @return array
* @return string[]
*/
public function getUserPermissions()
{
Expand All @@ -291,6 +269,9 @@ public function getUserPermissions()
return $permissions;
}

/**
* @return string[]
*/
public function getOwnerPermissions()
{
return self::$ownerPermissions;
Expand All @@ -308,8 +289,6 @@ public function isOwner()
}

/**
* Gets security handler.
*
* @return AclSecurityHandlerInterface
*/
public function getSecurityHandler()
Expand All @@ -330,6 +309,8 @@ public function getSecurityInformation()

/**
* Cache masks.
*
* @return void
*/
protected function updateMasks()
{
Expand Down
10 changes: 6 additions & 4 deletions src/Util/AdminObjectAclManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function createAclRolesForm(AdminObjectAclData $data)
}

/**
* Updates ACL users.
* @return void
*/
public function updateAclUsers(AdminObjectAclData $data)
{
Expand All @@ -132,7 +132,7 @@ public function updateAclUsers(AdminObjectAclData $data)
}

/**
* Updates ACL roles.
* @return void
*/
public function updateAclRoles(AdminObjectAclData $data)
{
Expand All @@ -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)
{
Expand All @@ -162,6 +162,8 @@ public function updateAcl(AdminObjectAclData $data)
/**
* @param \Traversable<int|string, UserInterface|string> $aclValues
*
* @return void
*
* @phpstan-param \Traversable<array-key, UserInterface|string> $aclValues
*/
protected function buildAcl(AdminObjectAclData $data, FormInterface $form, \Traversable $aclValues)
Expand Down
Loading

0 comments on commit 4c97daf

Please sign in to comment.