fix: SA: Fix many critical rules.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera 2021-11-16 17:13:39 +01:00
parent db2010082a
commit 5432242376
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
19 changed files with 345 additions and 655 deletions

View File

@ -90,51 +90,21 @@ parameters:
count: 1
path: src/Bundle/ChillTaskBundle/Controller/TaskController.php
-
message: "#^Undefined variable\\: \\$id$#"
count: 1
path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php
-
message: "#^Call to an undefined method Chill\\\\MainBundle\\\\CRUD\\\\Controller\\\\AbstractCRUDController\\:\\:getRoleFor\\(\\)\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php
-
message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:tempOutput\\(\\)\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php
-
message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Controller\\\\AdminCountryCRUDController\\:\\:\\$paginatorFactory\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Controller/AdminCountryCRUDController.php
-
message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Controller\\\\UserController\\:\\:createEditForm\\(\\)\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Controller/UserController.php
-
message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Entity\\\\RoleScope\\:\\:\\$new\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Entity/RoleScope.php
-
message: "#^Undefined variable\\: \\$current$#"
count: 1
path: src/Bundle/ChillMainBundle/Pagination/PageGenerator.php
-
message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Routing\\\\MenuComposer\\:\\:\\$routeCollection\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Routing/MenuComposer.php
-
message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Search\\\\SearchApiResult\\:\\:\\$relevance\\.$#"
count: 2
path: src/Bundle/ChillMainBundle/Search/SearchApiResult.php
-
message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Security\\\\Authorization\\\\AbstractChillVoter\\:\\:getSupportedAttributes\\(\\)\\.$#"
count: 1
@ -155,46 +125,6 @@ parameters:
count: 3
path: src/Bundle/ChillPersonBundle/Controller/PersonController.php
-
message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Controller\\\\TimelinePersonController\\:\\:\\$authorizationHelper\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php
-
message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\DataFixtures\\\\ORM\\\\LoadHousehold\\:\\:\\$personIds\\.$#"
count: 2
path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadHousehold.php
-
message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Form\\\\CreationPersonType\\:\\:\\$centerTransformer\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Form/CreationPersonType.php
-
message: "#^Access to an undefined property Chill\\\\ReportBundle\\\\Timeline\\\\TimelineReportProvider\\:\\:\\$security\\.$#"
count: 4
path: src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php
-
message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Entity\\\\AsideActivityCategory\\:\\:\\$oldParent\\.$#"
count: 2
path: src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php
-
message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityCategoryType\\:\\:\\$categoryRender\\.$#"
count: 2
path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityCategoryType.php
-
message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityFormType\\:\\:\\$translatableStringHelper\\.$#"
count: 1
path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php
-
message: "#^Access to an undefined property Chill\\\\CalendarBundle\\\\DataFixtures\\\\ORM\\\\LoadCalendarRange\\:\\:\\$userRepository\\.$#"
count: 2
path: src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCalendarRange.php
-
message: "#^Call to an undefined method Chill\\\\ThirdPartyBundle\\\\Form\\\\Type\\\\PickThirdPartyTypeCategoryType\\:\\:transform\\(\\)\\.$#"
count: 1

View File

@ -44,13 +44,15 @@ class AsideActivityCategory
* @ORM\ManyToOne(targetEntity=AsideActivityCategory::class, inversedBy="children")
* @ORM\JoinColumn(nullable=true)
*/
private $parent;
private AsideActivityCategory $parent;
/**
* @ORM\OneToMany(targetEntity=AsideActivityCategory::class, mappedBy="parent")
*/
private $children;
private AsideActivityCategory $oldParent;
public function __construct()
{
$this->children = new ArrayCollection();

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\AsideActivityBundle\Form;
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
@ -14,12 +16,11 @@ use Symfony\Component\Form\FormBuilderInterface;
final class AsideActivityCategoryType extends AbstractType
{
private CategoryRender $categoryRender;
protected $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper, CategoryRender $categoryRender)
{
$this->translatableStringHelper = $translatableStringHelper;
public function __construct(
CategoryRender $categoryRender
) {
$this->categoryRender = $categoryRender;
}

View File

@ -25,18 +25,16 @@ use Symfony\Component\Templating\EngineInterface;
final class AsideActivityFormType extends AbstractType
{
protected array $timeChoices;
private array $timeChoices;
private TokenStorageInterface $storage;
private CategoryRender $categoryRender;
public function __construct (
TranslatableStringHelper $translatableStringHelper,
ParameterBagInterface $parameterBag,
TokenStorageInterface $storage,
CategoryRender $categoryRender
){
$this->timeChoices = $parameterBag->get('chill_aside_activity.form.time_duration');
$this->translatableStringHelper = $translatableStringHelper;
$this->storage = $storage;
$this->categoryRender = $categoryRender;
}

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Entity\CalendarRange;
@ -15,6 +17,10 @@ use Doctrine\Persistence\ObjectManager;
class LoadCalendarRange extends Fixture implements FixtureGroupInterface, OrderedFixtureInterface
{
private UserRepository $userRepository;
public static array $references = [];
public function __construct(
UserRepository $userRepository
) {
@ -31,8 +37,6 @@ class LoadCalendarRange extends Fixture implements FixtureGroupInterface, Ordere
return ['calendar'];
}
public static $references = [];
public function load(ObjectManager $manager): void
{
$arr = range(-50, 50);

View File

@ -3,7 +3,6 @@
namespace Chill\AMLI\FamilyMembersBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
@ -13,26 +12,15 @@ use Chill\AMLI\FamilyMembersBundle\Form\FamilyMemberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Translation\TranslatorInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Annotation\Route;
class FamilyMemberController extends Controller
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
protected EntityManagerInterface $em;
/**
*
* @var TranslatorInterface
*/
protected $translator;
protected TranslatorInterface $translator;
/**
*
* @var LoggerInterface
*/
protected $chillMainLogger;
protected LoggerInterface $chillMainLogger;
public function __construct(
EntityManagerInterface $em,

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\MainBundle\CRUD\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -14,31 +16,28 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Translation\TranslatorInterface;
class AbstractCRUDController extends AbstractController
abstract class AbstractCRUDController extends AbstractController
{
/**
* The crud configuration
*
* This configuration si defined by `chill_main['crud']` or `chill_main['apis']`
*
* @var array
*/
protected array $crudConfig = [];
/**
* get the instance of the entity with the given id
*
* @param string $id
* @return object
* @throw Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the object is not found
*/
protected function getEntity($action, $id, Request $request): object
protected function getEntity($action, string $id, Request $request): object
{
$e = $this->getDoctrine()
$e = $this
->getDoctrine()
->getRepository($this->getEntityClass())
->find($id);
if (NULL === $e) {
if (null === $e) {
throw $this->createNotFoundException(sprintf("The object %s for id %s is not found", $this->getEntityClass(), $id));
}
@ -48,15 +47,11 @@ class AbstractCRUDController extends AbstractController
/**
* Create an entity.
*
* @param string $action
* @param Request $request
* @return object
*/
protected function createEntity(string $action, Request $request): object
{
$type = $this->getEntityClass();
return new $type;
return $this->getEntityClass();
}
/**
@ -64,18 +59,13 @@ class AbstractCRUDController extends AbstractController
*
* By default, count all entities. You can customize the query by
* using the method `customizeQuery`.
*
* @param string $action
* @param Request $request
* @return int
*/
protected function countEntities(string $action, Request $request, $_format): int
{
return $this->buildQueryEntities($action, $request)
->select('COUNT(e)')
->getQuery()
->getSingleScalarResult()
;
->getSingleScalarResult();
}
/**
@ -87,7 +77,6 @@ class AbstractCRUDController extends AbstractController
* The method `orderEntity` is called internally to order entities.
*
* It returns, by default, a query builder.
*
*/
protected function queryEntities(string $action, Request $request, string $_format, PaginatorInterface $paginator)
{
@ -101,7 +90,6 @@ class AbstractCRUDController extends AbstractController
/**
* Add ordering fields in the query build by self::queryEntities
*
*/
protected function orderQuery(string $action, $query, Request $request, PaginatorInterface $paginator, $_format)
{
@ -118,8 +106,6 @@ class AbstractCRUDController extends AbstractController
*
* The alias for the entity is "e".
*
* @param string $action
* @param Request $request
* @return QueryBuilder
*/
protected function buildQueryEntities(string $action, Request $request)
@ -127,8 +113,7 @@ class AbstractCRUDController extends AbstractController
$qb = $this->getDoctrine()->getManager()
->createQueryBuilder()
->select('e')
->from($this->getEntityClass(), 'e')
;
->from($this->getEntityClass(), 'e');
$this->customizeQuery($action, $request, $qb);
@ -138,7 +123,7 @@ class AbstractCRUDController extends AbstractController
protected function customizeQuery(string $action, Request $request, $query): void {}
/**
* Get the result of the query
* Get the result of the query.
*/
protected function getQueryResult(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query)
{
@ -151,7 +136,7 @@ class AbstractCRUDController extends AbstractController
}
/**
* method used by indexAction
* Method used by indexAction.
*/
protected function onPreIndexBuildQuery(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator): ?Response
{
@ -159,7 +144,7 @@ class AbstractCRUDController extends AbstractController
}
/**
* method used by indexAction
* Method used by indexAction.
*/
protected function onPostIndexBuildQuery(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $query): ?Response
{
@ -167,7 +152,7 @@ class AbstractCRUDController extends AbstractController
}
/**
* method used by indexAction
* Method used by indexAction.
*/
protected function onPostIndexFetchQuery(string $action, Request $request, string $_format, int $totalItems, PaginatorInterface $paginator, $entities): ?Response
{
@ -176,9 +161,9 @@ class AbstractCRUDController extends AbstractController
/**
* Get the complete FQDN of the class
* Get the FQDN of the class.
*
* @return string the complete fqdn of the class
* @return string The FQDN of the class
*/
protected function getEntityClass(): string
{
@ -186,7 +171,7 @@ class AbstractCRUDController extends AbstractController
}
/**
* called on post fetch entity
* Called on post fetch entity.
*/
protected function onPostFetchEntity(string $action, Request $request, $entity, $_format): ?Response
{
@ -194,7 +179,7 @@ class AbstractCRUDController extends AbstractController
}
/**
* Called on post check ACL
* Called on post check ACL.
*/
protected function onPostCheckACL(string $action, Request $request, string $_format, $entity): ?Response
{
@ -214,12 +199,12 @@ class AbstractCRUDController extends AbstractController
*/
protected function checkACL(string $action, Request $request, string $_format, $entity = null)
{
// @TODO: Implements abstract getRoleFor method or do it in the interface.
$this->denyAccessUnlessGranted($this->getRoleFor($action, $request, $entity, $_format), $entity);
}
/**
*
* @return string the crud name
* @return string The crud name.
*/
protected function getCrudName(): string
{
@ -241,9 +226,6 @@ class AbstractCRUDController extends AbstractController
$this->crudConfig = $config;
}
/**
* @return PaginatorFactory
*/
protected function getPaginatorFactory(): PaginatorFactory
{
return $this->container->get('chill_main.paginator_factory');
@ -254,9 +236,6 @@ class AbstractCRUDController extends AbstractController
return $this->get('validator');
}
/**
* @return array
*/
public static function getSubscribedServices(): array
{
return \array_merge(

View File

@ -1,7 +1,10 @@
<?php
declare(strict_types=1);
namespace Chill\MainBundle\Command;
use Chill\MainBundle\Repository\UserRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@ -23,81 +26,34 @@ use League\Csv\Writer;
class ChillImportUsersCommand extends Command
{
protected EntityManagerInterface $em;
/**
*
* @var EntityManagerInterface
*/
protected $em;
protected ValidatorInterface $validator;
/**
*
* @var ValidatorInterface
*/
protected $validator;
protected LoggerInterface $logger;
/**
*
* @var LoggerInterface
*/
protected $logger;
protected UserPasswordEncoderInterface $passwordEncoder;
/**
*
* @var UserPasswordEncoderInterface
*/
protected $passwordEncoder;
protected UserRepository $userRepository;
/**
*
* @var \Chill\MainBundle\Repository\UserRepository
*/
protected $userRepository;
protected bool $doChanges = true;
/**
*
* @var bool
*/
protected $doChanges = true;
protected OutputInterface $tempOutput;
/**
*
* @var OutputInterface
*/
protected $tempOutput;
/**
*
* @var InputInterface
*/
protected $tempInput;
protected InputInterface $tempInput;
/**
* Centers and aliases.
*
* key are aliases, values are an array of centers
*
* @var array
*/
protected $centers = [];
protected array $centers;
/**
*
* @var array
*/
protected $permissionGroups = [];
protected array $permissionGroups;
/**
*
* @var array
*/
protected $groupCenters = [];
protected array $groupCenters;
/**
*
* @var Writer
*/
protected $output = null;
protected Writer $output;
public function __construct(
EntityManagerInterface $em,
@ -110,14 +66,11 @@ class ChillImportUsersCommand extends Command
$this->validator = $validator;
$this->logger = $logger;
$this->userRepository = $em->getRepository(User::class);
parent::__construct('chill:main:import-users');
}
protected function configure()
{
$this
@ -126,8 +79,7 @@ class ChillImportUsersCommand extends Command
->addArgument('csvfile', InputArgument::REQUIRED, 'Path to the csv file. Columns are: `username`, `email`, `center` (can contain alias), `permission group`')
->addOption('grouping-centers', null, InputOption::VALUE_OPTIONAL, 'Path to a csv file to aggregate multiple centers into a single alias')
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Do not commit the changes')
->addOption('csv-dump', null, InputOption::VALUE_REQUIRED, 'A path to dump a summary of the created file')
;
->addOption('csv-dump', null, InputOption::VALUE_REQUIRED, 'A path to dump a summary of the created file');
}
protected function execute(InputInterface $input, OutputInterface $output)
@ -309,21 +261,14 @@ class ChillImportUsersCommand extends Command
}
return $this->permissionGroups[$alias];
} else {
$this->logger->error("Error while responding to a a question");
$this->tempOutput("Ok, I accept, but I do not know what to do. Please try again.");
throw new \RuntimeException("Error while responding to a question");
}
$this->logger->error('Error while responding to a a question');
$this->tempOutput->writeln('Ok, I accept, but I do not know what to do. Please try again.');
throw new \RuntimeException('Error while responding to a question');
}
/**
*
* @param Center $center
* @param \Chill\MainBundle\Command\PermissionGroup $pg
* @return GroupCenter
*/
protected function createOrGetGroupCenter(Center $center, PermissionsGroup $pg): GroupCenter
{
if (\array_key_exists($center->getId(), $this->groupCenters)) {

View File

@ -1,20 +1,12 @@
<?php
declare(strict_types=1);
namespace Chill\MainBundle\Controller;
use Chill\MainBundle\CRUD\Controller\CRUDController;
use Chill\MainBundle\Entity\Country;
use Chill\MainBundle\Pagination\PaginatorFactory;
/**
*
*
*/
class AdminCountryCRUDController extends CRUDController
{
function __construct(PaginatorFactory $paginator)
{
$this->paginatorFactory = $paginator;
}
}

View File

@ -136,20 +136,17 @@ class UserController extends CRUDController
]);
}
/**
*
*
* @param User $user
* @return \Symfony\Component\Form\Form
*/
private function createEditPasswordForm(User $user)
private function createEditPasswordForm(User $user): FormInterface
{
return $this->createForm(UserPasswordType::class, null, array(
'user' => $user
))
return $this->createForm(
UserPasswordType::class,
null,
[
'user' => $user
]
)
->add('submit', SubmitType::class, array('label' => 'Change password'))
->remove('actual_password')
;
->remove('actual_password');
}
/**

View File

@ -1,23 +1,5 @@
<?php
/*
* Chill is a suite of a modules, Chill is a software for social workers
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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/>.
*/
namespace Chill\MainBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
@ -28,37 +10,29 @@ use Doctrine\Common\Collections\ArrayCollection;
* @ORM\Entity
* @ORM\Table(name="role_scopes")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region")
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class RoleScope
{
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
private int $id;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*/
private $role;
private string $role;
/**
* @var Scope
*
* @ORM\ManyToOne(
* targetEntity="Chill\MainBundle\Entity\Scope",
* inversedBy="roleScopes")
* @ORM\JoinColumn(nullable=true, name="scope_id")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/
private $scope;
private Scope $scope;
/**
* @var Collection
@ -69,10 +43,8 @@ class RoleScope
*/
private $permissionsGroups;
private bool $new;
/**
* RoleScope constructor.
*/
public function __construct() {
$this->new = true;
$this->permissionsGroups = new ArrayCollection();

View File

@ -1,44 +1,17 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2016 Champs-Libres Coopérative <info@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\Pagination;
/**
* PageGenerator associated with a Paginator
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
* PageGenerator associated with a Paginator.
*/
class PageGenerator implements \Iterator
{
/**
*
* @var Paginator
*/
protected $paginator;
protected Paginator $paginator;
/**
*
* @var int
*/
protected $current = 1;
protected int $current = 1;
public function __construct(Paginator $paginator)
{

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\MainBundle\Routing;
use Symfony\Component\Routing\RouteCollection;
@ -8,7 +10,6 @@ use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\Translation\TranslatorInterface;
/**
* This class permit to build menu from the routing information
* stored in each bundle.
@ -20,29 +21,15 @@ use Symfony\Component\Translation\TranslatorInterface;
class MenuComposer
{
/**
*
* @var RouterInterface
*/
private $router;
private RouterInterface $router;
/**
*
* @var FactoryInterface
*/
private $menuFactory;
private FactoryInterface $menuFactory;
/**
*
* @var TranslatorInterface
*/
private $translator;
private TranslatorInterface $translator;
/**
*
* @var
*/
private $localMenuBuilders = [];
private array $localMenuBuilders = [];
private RouteCollection $routeCollection;
function __construct(

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\MainBundle\Search;
use Symfony\Component\Serializer\Annotation as Serializer;
@ -10,6 +12,8 @@ class SearchApiResult
private $result;
private float $relevance;
public function __construct(float $relevance)
{
$this->relevance = $relevance;

View File

@ -1,34 +1,17 @@
<?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;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Voter for Chill software.
*
* This abstract Voter provide generic methods to handle object specific to Chill
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
abstract class AbstractChillVoter extends Voter implements ChillVoterInterface
{
@ -39,6 +22,8 @@ abstract class AbstractChillVoter extends Voter implements ChillVoterInterface
. 'getSupportedAttributes and getSupportedClasses methods.',
E_USER_DEPRECATED);
// @TODO: getSupportedAttributes() should be created in here and made abstract or in ChillVoterInterface.
// @TODO: getSupportedClasses() should be created in here and made abstract or in ChillVoterInterface.
return \in_array($attribute, $this->getSupportedAttributes($attribute))
&& \in_array(\get_class($subject), $this->getSupportedClasses());
}
@ -49,7 +34,7 @@ abstract class AbstractChillVoter extends Voter implements ChillVoterInterface
. 'methods introduced by Symfony 3.0, and do not rely on '
. 'isGranted method', E_USER_DEPRECATED);
// @TODO: isGranted() should be created in here and made abstract or in ChillVoterInterface.
return $this->isGranted($attribute, $subject, $token->getUser());
}
}

View File

@ -1,66 +1,41 @@
<?php
/*
* Copyright (C) 2015 Champs-Libres Coopérative <info@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\Controller;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Privacy\PrivacyEvent;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Chill\MainBundle\Timeline\TimelineBuilder;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Role\Role;
class TimelinePersonController extends AbstractController
{
protected EventDispatcherInterface $eventDispatcher;
protected TimelineBuilder $timelineBuilder;
protected PaginatorFactory $paginatorFactory;
/**
* TimelinePersonController constructor.
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function __construct(
EventDispatcherInterface $eventDispatcher,
TimelineBuilder $timelineBuilder,
PaginatorFactory $paginatorFactory,
AuthorizationHelper $authorizationHelper
PaginatorFactory $paginatorFactory
) {
$this->eventDispatcher = $eventDispatcher;
$this->timelineBuilder = $timelineBuilder;
$this->paginatorFactory = $paginatorFactory;
$this->authorizationHelper = $authorizationHelper;
}
public function personAction(Request $request, $person_id)
{
$person = $this->getDoctrine()
->getRepository('ChillPersonBundle:Person')
->getRepository(Person::class)
->find($person_id);
if ($person === NULL) {

View File

@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\PersonBundle\Entity\Person;
@ -24,6 +26,8 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
private CONST NUMBER_OF_HOUSEHOLD = 10;
private array $personIds;
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
{
$this->editorFactory = $editorFactory;
@ -149,14 +153,14 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
private function preparePersonIds()
{
// @TODO: Remove this and make this service stateless
$this->personIds = $this->em
->createQuery('SELECT p.id FROM '.Person::class.' p '.
'JOIN p.center c '.
'WHERE c.name = :center '
)
->setParameter('center', 'Center A')
->getScalarResult()
;
->getScalarResult();
\shuffle($this->personIds);
}
@ -169,9 +173,7 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
for ($i=0; $i < $nb; $i++) {
$personId = \array_pop($this->personIds)['id'];
$persons[] = $this->em->getRepository(Person::class)
->find($personId)
;
$persons[] = $this->em->getRepository(Person::class)->find($personId);
}
return $persons;

View File

@ -1,28 +1,10 @@
<?php
/*
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.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\Form;
use Chill\MainBundle\Form\Event\CustomizeFormEvent;
use Chill\MainBundle\Repository\CenterRepository;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@ -30,12 +12,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeToStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\PickCenterType;
use Chill\PersonBundle\Form\Type\GenderType;
use Chill\MainBundle\Form\Type\DataTransformer\CenterTransformer;
use Chill\PersonBundle\Config\ConfigPersonAltNamesHelper;
use Chill\PersonBundle\Form\Type\PersonAltNameType;
@ -43,27 +22,19 @@ final class CreationPersonType extends AbstractType
{
// TODO: This is only used in test.
// TODO: See if this is still valid and update accordingly.
const NAME = 'chill_personbundle_person_creation';
public const NAME = 'chill_personbundle_person_creation';
private CenterRepository $centerRepository;
/**
*
* @var ConfigPersonAltNamesHelper
*/
protected $configPersonAltNamesHelper;
private ConfigPersonAltNamesHelper $configPersonAltNamesHelper;
private EventDispatcherInterface $dispatcher;
private bool $askCenters;
public function __construct(
CenterRepository $centerRepository,
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
EventDispatcherInterface $dispatcher,
ParameterBagInterface $parameterBag
) {
$this->centerTransformer = $centerRepository;
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
$this->dispatcher = $dispatcher;
$this->askCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];

View File

@ -1,22 +1,6 @@
<?php
/*
* Chill is a software for social workers
* Copyright (C) 2015 Champs Libres <info@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\ReportBundle\Timeline;
@ -45,7 +29,9 @@ class TimelineReportProvider implements TimelineProviderInterface
protected CustomFieldsHelper $customFieldsHelper;
protected $showEmptyValues;
protected bool $showEmptyValues;
private Security $security;
public function __construct(
EntityManager $em,
@ -53,8 +39,7 @@ class TimelineReportProvider implements TimelineProviderInterface
Security $security,
CustomFieldsHelper $customFieldsHelper,
$showEmptyValues
)
{
) {
$this->em = $em;
$this->helper = $helper;
$this->security = $security;