cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,18 +1,24 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Security;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
use function array_keys;
/**
* Helper which traverse all role to find parents
* Helper which traverse all role to find parents.
*/
class ParentRoleHelper
{
protected RoleHierarchyInterface $roleHierarchy;
/**
* The role in a hierarchy, given by the parameter
* `security.role_hierarchy.roles` from the container.
@@ -21,12 +27,14 @@ class ParentRoleHelper
*/
protected array $hierarchy;
protected RoleHierarchyInterface $roleHierarchy;
public function __construct(
RoleHierarchyInterface $roleHierarchy,
ParameterBagInterface $parameterBag
) {
$this->roleHierarchy = $roleHierarchy;
$this->hierarchy = $parameterBag->get('security.role_hierarchy.roles');
$this->hierarchy = $parameterBag->get('security.role_hierarchy.roles');
}
/**
@@ -35,14 +43,13 @@ class ParentRoleHelper
*
* The array contains always the current $role (which give access to himself)
*
* @param string $role
* @return string[] the role which give access to the given $role
*/
public function getParentRoles(string $role): array
{
$parentRoles = [$role];
// transform the roles from role hierarchy from string to Role
$roles = \array_keys($this->hierarchy);
$roles = array_keys($this->hierarchy);
foreach ($roles as $r) {
$childRoles = $this->roleHierarchy->getReachableRoleNames([$r]);
@@ -56,10 +63,11 @@ class ParentRoleHelper
}
/**
* Test if a parent role may give access to a given child role
* 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 $parentRole The role which should give access to $childRole
*
* @return bool true if the child role is granted by parent role
*/
public function isRoleReached($childRole, $parentRole): bool
@@ -69,5 +77,4 @@ class ParentRoleHelper
return in_array($childRole, $reachableRoles);
}
}