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,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;
}