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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user