apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -20,11 +20,6 @@ use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
use Psr\Log\LoggerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Traversable;
use UnexpectedValueException;
use function array_merge;
use function get_class;
/**
* Helper for authorizations.
@@ -44,7 +39,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* Filter an array of centers, return only center which are reachable.
*
* @param User $user The user
* @param User $user The user
* @param array $centers a list of centers which are going to be filtered
*/
public function filterReachableCenters(User $user, array $centers, mixed $role): array
@@ -63,10 +58,9 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* @deprecated use UserACLAwareRepositoryInterface::findUsersByReachedACL instead
*
*
* @return User[]
*/
public function findUsersReaching(string $role, array|\Chill\MainBundle\Entity\Center $center, null|array|\Chill\MainBundle\Entity\Scope $scope = null, bool $onlyEnabled = true): array
public function findUsersReaching(string $role, array|\Chill\MainBundle\Entity\Center $center, array|\Chill\MainBundle\Entity\Scope $scope = null, bool $onlyEnabled = true): array
{
return $this->userACLAwareRepository
->findUsersByReachedACL($role, $center, $scope, $onlyEnabled);
@@ -91,7 +85,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*
* @return list<Center>
*/
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
public function getReachableCenters(UserInterface $user, string $role, Scope $scope = null): array
{
if (!$user instanceof User) {
return [];
@@ -102,9 +96,9 @@ class AuthorizationHelper implements AuthorizationHelperInterface
foreach ($user->getGroupCenters() as $groupCenter) {
$permissionGroup = $groupCenter->getPermissionsGroup();
//iterate on roleScopes
// iterate on roleScopes
foreach ($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role is in the reachable roles
// check that the role is in the reachable roles
if ($this->isRoleReached($role, $roleScope->getRole())) {
if (null === $scope) {
$centers[spl_object_hash($groupCenter->getCenter())] = $groupCenter->getCenter();
@@ -128,6 +122,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
* Return all reachable circle for a given user, center and role.
*
* @param Center|Center[] $center
*
* @return Scope[]
*/
public function getReachableCircles(UserInterface $user, string $role, array|\Chill\MainBundle\Entity\Center $center)
@@ -136,7 +131,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
if (is_iterable($center)) {
foreach ($center as $c) {
$scopes = array_merge($scopes, $this->getReachableCircles($user, $role, $c));
$scopes = \array_merge($scopes, $this->getReachableCircles($user, $role, $c));
}
return $scopes;
@@ -144,11 +139,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
foreach ($user->getGroupCenters() as $groupCenter) {
if ($center->getId() === $groupCenter->getCenter()->getId()) {
//iterate on permissionGroup
// iterate on permissionGroup
$permissionGroup = $groupCenter->getPermissionsGroup();
//iterate on roleScopes
// iterate on roleScopes
foreach ($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role is in the reachable roles
// check that the role is in the reachable roles
if ($this->isRoleReached($role, $roleScope->getRole())) {
$scopes[] = $roleScope->getScope();
}
@@ -174,7 +169,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*/
public function userCanReachCenter(User $user, array|\Chill\MainBundle\Entity\Center $center): bool
{
if ($center instanceof Traversable) {
if ($center instanceof \Traversable) {
foreach ($center as $c) {
if ($c->userCanReachCenter($user, $c)) {
return true;
@@ -194,13 +189,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
return false;
}
throw new UnexpectedValueException(
sprintf(
'The entity given is not an instance of %s or an array of centers, %s given',
Center::class,
gettype($center)
)
);
throw new \UnexpectedValueException(sprintf('The entity given is not an instance of %s or an array of centers, %s given', Center::class, gettype($center)));
}
/**
@@ -229,7 +218,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* Test if a parent role may give access to a given child role.
*
* @param string $childRole The role we want to test if he is reachable
* @param string $childRole The role we want to test if he is reachable
* @param string $parentRole The role which should give access to $childRole
*
* @return bool true if the child role is granted by parent role
@@ -255,11 +244,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
// we cannot compare the objects: we must compare the ids here
if ($groupCenter->getCenter()->getId() === $center->getId()) {
$permissionGroup = $groupCenter->getPermissionsGroup();
//iterate on roleScopes
// iterate on roleScopes
foreach ($permissionGroup->getRoleScopes() as $roleScope) {
//check that the role allow to reach the required role
// check that the role allow to reach the required role
if ($this->isRoleReached($attribute, $roleScope->getRole())) {
//if yes, we have a right on something...
// if yes, we have a right on something...
// perform check on scope if necessary
if ($this->scopeResolverDispatcher->isConcerned($entity)) {// here, we should also check that the role need a scope
$scope = $this->scopeResolverDispatcher->resolveScope($entity);