fix: SA: Split critical issues in its own file.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 13:55:55 +01:00
parent c68bda5c9b
commit 8ede116cf5
12 changed files with 333 additions and 380 deletions

View File

@@ -1,35 +1,22 @@
<?php
/*
* Copyright (C) 2016 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\PersonBundle\Widget;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Templating\Widget\WidgetInterface;
use Doctrine\ORM\EntityRepository;
use Chill\PersonBundle\Repository\PersonRepository;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr;
use Doctrine\DBAL\Types\Types;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Role\Role;
use Doctrine\ORM\EntityManager;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Twig\Environment;
/**
@@ -42,45 +29,22 @@ use Twig\Environment;
*/
class PersonListWidget implements WidgetInterface
{
/**
* Repository for persons
*
* @var PersonRepository
*/
protected $personRepository;
protected PersonRepository $personRepository;
/**
* The entity manager
*
* @var EntityManager
*/
protected $entityManager;
protected EntityManagerInterface $entityManager;
/**
* the authorization helper
*
* @var AuthorizationHelper;
*/
protected $authorizationHelper;
protected AuthorizationHelperInterface $authorizationHelper;
/**
*
* @var TokenStorage
*/
protected $tokenStorage;
protected TokenStorageInterface $tokenStorage;
/**
*
* @var UserInterface
*/
protected $user;
protected UserInterface $user;
public function __construct(
PersonRepository $personRepostory,
EntityManager $em,
AuthorizationHelper $authorizationHelper,
TokenStorage $tokenStorage
) {
EntityManagerInterface $em,
AuthorizationHelperInterface $authorizationHelper,
TokenStorageInterface $tokenStorage
) {
$this->personRepository = $personRepostory;
$this->authorizationHelper = $authorizationHelper;
$this->tokenStorage = $tokenStorage;
@@ -88,11 +52,8 @@ class PersonListWidget implements WidgetInterface
}
/**
*
* @param type $place
* @param array $context
* @param array $config
* @return string
*/
public function render(Environment $env, $place, array $context, array $config)
{
@@ -134,8 +95,10 @@ class PersonListWidget implements WidgetInterface
. "implements %s", $config['filtering_class'],
PersonListWidget\PersonFilteringInterface::class));
}
$ids = $filteringClass->getPersonIds($this->entityManager,
$this->getUser());
$ids = $filteringClass->getPersonIds(
$this->entityManager,
$this->getUser()
);
$in = (new Expr())->in('person.id', ':ids');
$and->add($in);
$qb->setParameter('ids', $ids);
@@ -178,12 +141,7 @@ class PersonListWidget implements WidgetInterface
);
}
/**
*
* @return UserInterface
* @throws \RuntimeException
*/
private function getUser()
private function getUser(): UserInterface
{
$token = $this->tokenStorage->getToken();
@@ -193,9 +151,10 @@ class PersonListWidget implements WidgetInterface
$user = $token->getUser();
if (!$user instanceof UserInterface || $user == null) {
throw new \RuntimeException("the user should implement UserInterface. "
. "Are you logged in ?");
if ($user === null) {
throw new \RuntimeException(
'The user should implement UserInterface. Are you logged in ?'
);
}
return $user;