cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,31 +1,40 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Entity\Household\Household;
use Chill\PersonBundle\Entity\Household\Position;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Household\MembersEditor;
use Chill\PersonBundle\Household\MembersEditorFactory;
use DateTimeImmutable;
use Symfony\Component\Serializer\Exception;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Exception;
use Chill\PersonBundle\Household\MembersEditorFactory;
use Chill\PersonBundle\Household\MembersEditor;
use function array_key_exists;
class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwareInterface
{
private MembersEditorFactory $factory;
use DenormalizerAwareTrait;
private MembersEditorFactory $factory;
public function __construct(MembersEditorFactory $factory)
{
$this->factory = $factory;
}
public function denormalize($data, string $type, string $format = null, array $context = [])
public function denormalize($data, string $type, ?string $format = null, array $context = [])
{
// some test about schema first...
$this->performChecks($data);
@@ -33,23 +42,16 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
// route to "leave movement" (all concerned leave household)
// or "move to another household" (all concerned go to another
// household)
if (NULL === $data['destination']) {
if (null === $data['destination']) {
return $this->denormalizeLeave($data, $type, $format, $context);
}
return $this->denormalizeMove($data, $type, $format, $context);
}
private function performChecks($data): void
public function supportsDenormalization($data, string $type, ?string $format = null)
{
if (NULL == $data['concerned'] ?? NULL
&& FALSE === ·\is_array('concerned')) {
throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'");
}
if (FALSE === \array_key_exists('destination', $data)) {
throw new Exception\UnexpectedValueException("The schema does not have any key 'destination'");
}
return MembersEditor::class === $type;
}
protected function denormalizeLeave($data, string $type, string $format, array $context = [])
@@ -57,18 +59,26 @@ 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);
$startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::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
);
if (
NULL === $person
&& NULL === $startDate
null === $person
&& null === $startDate
) {
throw new Exception\InvalidArgumentException("position with ".
"key $key could not be denormalized: missing ".
"person or start_date.");
throw new Exception\InvalidArgumentException('position with ' .
"key {$key} could not be denormalized: missing " .
'person or start_date.');
}
$editor->leaveMovement($startDate, $person);
@@ -82,46 +92,73 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar
$householdContext = $context;
$householdContext['groups'][] = 'create';
$household = $this->denormalizer->denormalize($data['destination'], Household::class,
$format, $householdContext);
$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");
if (null === $household) {
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);
$position = $this->denormalizer->denormalize($concerned['position'] ?? null, Position::class,
$format, $context);
$startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::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,
$format,
$context
);
$holder = (bool) $concerned['holder'] ?? false;
$comment = (string) $concerned['comment'] ?? false;
if (
NULL === $person
&& NULL === $position
&& NULL === $startDate
null === $person
&& null === $position
&& null === $startDate
) {
throw new Exception\InvalidArgumentException("position with ".
"key $key could not be denormalized: missing ".
"person, position or start_date.");
throw new Exception\InvalidArgumentException('position with ' .
"key {$key} could not be denormalized: missing " .
'person, position or start_date.');
}
$editor->addMovement($startDate, $person, $position, $holder,
$comment);
$editor->addMovement(
$startDate,
$person,
$position,
$holder,
$comment
);
}
return $editor;
}
public function supportsDenormalization($data, string $type, string $format = null)
private function performChecks($data): void
{
return $type === MembersEditor::class;
}
if (null == $data['concerned'] ?? null
&& false === ·\is_array('concerned')) {
throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'");
}
if (false === array_key_exists('destination', $data)) {
throw new Exception\UnexpectedValueException("The schema does not have any key 'destination'");
}
}
}