fix: SA: Fix "...invoked with..." rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 12:16:02 +01:00
parent a3eb23478a
commit c68bda5c9b
11 changed files with 183 additions and 355 deletions

View File

@@ -1,21 +1,6 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Security\Authorization;
@@ -43,7 +28,6 @@ use Chill\MainBundle\Entity\RoleScope;
* Helper for authorizations.
*
* Provides methods for user and entities information.
*
*/
class AuthorizationHelper implements AuthorizationHelperInterface
{
@@ -74,11 +58,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* Determines if a user is active on this center
*
* If
*
* @param User $user
* @param Center|Center[] $center May be an array of center
* @return bool
*/
public function userCanReachCenter(User $user, $center): bool
{
@@ -89,7 +69,9 @@ class AuthorizationHelper implements AuthorizationHelperInterface
}
}
return false;
} elseif ($center instanceof Center) {
}
if ($center instanceof Center) {
foreach ($user->getGroupCenters() as $groupCenter) {
if ($center->getId() === $groupCenter->getCenter()->getId()) {
return true;
@@ -99,12 +81,16 @@ class AuthorizationHelper implements AuthorizationHelperInterface
return false;
}
throw new \UnexpectedValueException(sprintf("The entity given is not an ".
"instance of %s, %s given", Center::class, get_class($center)));
throw new \UnexpectedValueException(
sprintf(
'The entity given is not an instance of %s, %s given',
Center::class,
get_class($center)
)
);
}
/**
*
* Determines if the user has access to the given entity.
*
* if the entity implements Chill\MainBundle\Entity\HasScopeInterface,
@@ -243,7 +229,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
}
foreach ($centers as $center) {
if ($this->userCanReachCenter($user, $center, $role)) {
if ($this->userCanReachCenter($user, $center)) {
$results[] = $center;
}
}