mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
fix: SA: Split critical issues in its own file.
SA stands for Static Analysis.
This commit is contained in:
@@ -1044,9 +1044,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
if (count($this->getPersons()) === 0){
|
||||
return null;
|
||||
} else {
|
||||
return $this->getPersons()->first()->getCenter();
|
||||
}
|
||||
|
||||
return $this->getPersons()->first()->getCenter();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1116,7 +1116,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
if ($this->getPersonLocation() instanceof Person) {
|
||||
return 'person';
|
||||
} elseif ($this->getAddressLocation() instanceof Address) {
|
||||
}
|
||||
|
||||
if ($this->getAddressLocation() instanceof Address) {
|
||||
return 'address';
|
||||
} else {
|
||||
return 'none';
|
||||
@@ -1137,11 +1139,11 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
public function getGroupSequence()
|
||||
{
|
||||
if ($this->getStep() == self::STEP_DRAFT)
|
||||
{
|
||||
if ($this->getStep() == self::STEP_DRAFT) {
|
||||
return [[self::STEP_DRAFT]];
|
||||
} elseif ($this->getStep() == self::STEP_CONFIRMED)
|
||||
{
|
||||
}
|
||||
|
||||
if ($this->getStep() == self::STEP_CONFIRMED) {
|
||||
return [[self::STEP_DRAFT, self::STEP_CONFIRMED]];
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Repository\AccompanyingPeriod;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
@@ -34,7 +36,7 @@ final class AccompanyingPeriodWorkRepository implements ObjectRepository
|
||||
|
||||
public function findOneBy(array $criteria): ?AccompanyingPeriodWork
|
||||
{
|
||||
return $this->findOneBy($criteria);
|
||||
return $this->repository->findOneBy($criteria);
|
||||
}
|
||||
|
||||
public function getClassName()
|
||||
|
@@ -1,22 +1,7 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* 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\Search;
|
||||
|
||||
use Chill\MainBundle\Search\AbstractSearch;
|
||||
@@ -38,7 +23,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
protected PaginatorFactory $paginatorFactory;
|
||||
protected PersonACLAwareRepositoryInterface $personACLAwareRepository;
|
||||
|
||||
const NAME = "person_regular";
|
||||
public const NAME = "person_regular";
|
||||
|
||||
private const POSSIBLE_KEYS = [
|
||||
'_default', 'firstname', 'lastname', 'birthdate', 'birthdate-before',
|
||||
@@ -102,7 +87,9 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION],
|
||||
'paginator' => $paginator
|
||||
));
|
||||
} elseif ($format === 'json') {
|
||||
}
|
||||
|
||||
if ($format === 'json') {
|
||||
return [
|
||||
'results' => $this->search($terms, $start, $limit, \array_merge($options, [ 'simplify' => true ])),
|
||||
'pagination' => [
|
||||
@@ -113,14 +100,9 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $pattern
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
* @param array $options
|
||||
* @return Person[]
|
||||
*/
|
||||
protected function search(array $terms, $start, $limit, array $options = array())
|
||||
protected function search(array $terms, int $start, int $limit, array $options = [])
|
||||
{
|
||||
[
|
||||
'_default' => $default,
|
||||
@@ -131,7 +113,6 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
|
||||
'birthdate-after' => $birthdateAfter,
|
||||
'gender' => $gender,
|
||||
'nationality' => $countryCode,
|
||||
|
||||
] = $terms + \array_fill_keys(self::POSSIBLE_KEYS, null);
|
||||
|
||||
foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) {
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
@@ -33,14 +35,14 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
|
||||
// household)
|
||||
if (NULL === $data['destination']) {
|
||||
return $this->denormalizeLeave($data, $type, $format, $context);
|
||||
} else {
|
||||
return $this->denormalizeMove($data, $type, $format, $context);
|
||||
}
|
||||
|
||||
return $this->denormalizeMove($data, $type, $format, $context);
|
||||
}
|
||||
|
||||
private function performChecks($data): void
|
||||
{
|
||||
if (NULL == $data['concerned'] ?? NULL
|
||||
if (NULL == $data['concerned'] ?? NULL
|
||||
&& FALSE === ·\is_array('concerned')) {
|
||||
throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'");
|
||||
}
|
||||
@@ -55,8 +57,8 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
|
||||
$editor = $this->factory->createEditor(null);
|
||||
|
||||
foreach ($data['concerned'] as $key => $concerned) {
|
||||
$person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class,
|
||||
$format, $context);
|
||||
$person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class,
|
||||
$format, $context);
|
||||
$startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::class,
|
||||
$format, $context);
|
||||
|
||||
@@ -80,18 +82,18 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
|
||||
$householdContext = $context;
|
||||
$householdContext['groups'][] = 'create';
|
||||
|
||||
$household = $this->denormalizer->denormalize($data['destination'], Household::class,
|
||||
$household = $this->denormalizer->denormalize($data['destination'], Household::class,
|
||||
$format, $householdContext);
|
||||
|
||||
if (NULL === $household) {
|
||||
throw new Exception\InvalidArgumentException("household could not be denormalized. Impossible to process");
|
||||
throw new Exception\InvalidArgumentException("household could not be denormalized. Impossible to process");
|
||||
}
|
||||
|
||||
$editor = $this->factory->createEditor($household);
|
||||
|
||||
foreach ($data['concerned'] as $key => $concerned) {
|
||||
$person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class,
|
||||
$format, $context);
|
||||
$person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class,
|
||||
$format, $context);
|
||||
$position = $this->denormalizer->denormalize($concerned['position'] ?? null, Position::class,
|
||||
$format, $context);
|
||||
$startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::class,
|
||||
@@ -110,10 +112,10 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
|
||||
"person, position or start_date.");
|
||||
}
|
||||
|
||||
$editor->addMovement($startDate, $person, $position, $holder,
|
||||
$editor->addMovement($startDate, $person, $position, $holder,
|
||||
$comment);
|
||||
}
|
||||
|
||||
|
||||
return $editor;
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,7 @@ class PersonNormalizer implements
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
}
|
||||
|
||||
public function normalize($person, string $format = null, array $context = array())
|
||||
public function normalize($person, string $format = null, array $context = [])
|
||||
{
|
||||
/** @var Household $household */
|
||||
$household = $person->getCurrentHousehold();
|
||||
@@ -128,22 +128,44 @@ class PersonNormalizer implements
|
||||
$person = new Person();
|
||||
}
|
||||
|
||||
foreach (['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender']
|
||||
as $item) {
|
||||
if (\array_key_exists($item, $data)) {
|
||||
$person->{'set'.\ucfirst($item)}($data[$item]);
|
||||
$properties = ['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender'];
|
||||
|
||||
$properties = array_filter(
|
||||
$properties,
|
||||
static fn (string $property): bool => array_key_exists($property, $data)
|
||||
);
|
||||
|
||||
foreach ($properties as $item) {
|
||||
$callable = [$person, sprintf('set%s', ucfirst($item))];
|
||||
|
||||
if (is_callable($callable)) {
|
||||
$closure = \Closure::fromCallable($callable);
|
||||
|
||||
$closure($data[$item]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ([
|
||||
$propertyToClassMapping = [
|
||||
'birthdate' => \DateTime::class,
|
||||
'deathdate' => \DateTime::class,
|
||||
'center' => Center::class
|
||||
] as $item => $class) {
|
||||
if (\array_key_exists($item, $data)) {
|
||||
$object = $this->denormalizer->denormalize($data[$item], $class, $format, $context);
|
||||
if ($object instanceof $class) {
|
||||
$person->{'set'.\ucfirst($item)}($object);
|
||||
'center' => Center::class,
|
||||
];
|
||||
|
||||
$propertyToClassMapping = array_filter(
|
||||
$propertyToClassMapping,
|
||||
static fn (string $item): bool => array_key_exists($item, $data)
|
||||
);
|
||||
|
||||
foreach ($propertyToClassMapping as $item => $class) {
|
||||
$object = $this->denormalizer->denormalize($data[$item], $class, $format, $context);
|
||||
|
||||
if ($object instanceof $class) {
|
||||
$callable = [$object, sprintf('set%s', ucfirst($item))];
|
||||
|
||||
if (is_callable($callable)) {
|
||||
$closure = \Closure::fromCallable($callable);
|
||||
|
||||
$closure($object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -22,6 +22,8 @@ namespace Chill\PersonBundle\Widget\PersonListWidget;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,8 +80,7 @@ interface PersonFilteringInterface
|
||||
}
|
||||
* ```
|
||||
*
|
||||
* @param EntityManager $em
|
||||
* @return int[] an array of persons id to show
|
||||
*/
|
||||
public function getPersonIds(EntityManager $em, User $user);
|
||||
public function getPersonIds(EntityManagerInterface $em, UserInterface $user);
|
||||
}
|
||||
|
Reference in New Issue
Block a user