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,29 +1,27 @@
<?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.
*/
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\Goal;
use Chill\PersonBundle\Entity\SocialWork\Result;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Serializer\Exception\BadMethodCallException;
use Symfony\Component\Serializer\Exception\ExceptionInterface;
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
use function array_key_exists;
use function array_merge;
use function in_array;
use function is_array;
/**
* This denormalizer rely on AbstractNormalizer for most of the job, and
@@ -34,15 +32,14 @@ class AccompanyingPeriodWorkDenormalizer implements DenormalizerAwareInterface,
use DenormalizerAwareTrait;
use ObjectToPopulateTrait;
private AccompanyingPeriodWorkRepository $workRepository;
public const GROUP_CREATE = 'accompanying_period_work:create';
public const GROUP_EDIT = 'accompanying_period_work:edit';
private EntityManagerInterface $em;
public const GROUP_CREATE = 'accompanying_period_work:create';
public const GROUP_EDIT = 'accompanying_period_work:edit';
private AccompanyingPeriodWorkRepository $workRepository;
/**
* @param AccompanyingPeriodWorkRepository $workRepository
*/
public function __construct(
AccompanyingPeriodWorkRepository $workRepository,
EntityManagerInterface $em
@@ -51,37 +48,46 @@ class AccompanyingPeriodWorkDenormalizer implements DenormalizerAwareInterface,
$this->em = $em;
}
/**
* @inheritDoc
*/
public function denormalize($data, string $type, string $format = null, array $context = [])
public function denormalize($data, string $type, ?string $format = null, array $context = [])
{
$work = $this->denormalizer->denormalize($data, $type, $format, \array_merge($context,
['skip' => self::class]));
$work = $this->denormalizer->denormalize($data, $type, $format, array_merge(
$context,
['skip' => self::class]
));
if (\in_array('accompanying_period_work:edit', $context['groups'] ?? [])) {
if (in_array('accompanying_period_work:edit', $context['groups'] ?? [])) {
$this->handleEvaluationCollection($data, $work, $format, $context);
}
return $work;
}
public function supportsDenormalization($data, string $type, ?string $format = null, array $context = []): bool
{
return AccompanyingPeriodWork::class === $type
&& self::class !== ($context['skip'] ?? null)
&& is_array($data)
&& array_key_exists('type', $data)
&& 'accompanying_period_work' === $data['type'];
}
private function handleEvaluationCollection(array $data, AccompanyingPeriodWork $work, string $format, array $context)
{
$dataById = [];
$dataWithoutId = [];
foreach ($data['accompanyingPeriodWorkEvaluations'] as $e) {
if (\array_key_exists('id', $e)) {
$dataById[$e['id']] = $e;
} else {
$dataWithoutId[] = $e;
}
if (array_key_exists('id', $e)) {
$dataById[$e['id']] = $e;
} else {
$dataWithoutId[] = $e;
}
}
// partition the separate kept evaluations and removed one
list($kept, $removed) = $work->getAccompanyingPeriodWorkEvaluations()
[$kept, $removed] = $work->getAccompanyingPeriodWorkEvaluations()
->partition(
fn(int $key, AccompanyingPeriodWorkEvaluation $a) => \array_key_exists($a->getId(), $dataById)
fn (int $key, AccompanyingPeriodWorkEvaluation $a) => array_key_exists($a->getId(), $dataById)
);
// remove the evaluations from work
@@ -92,13 +98,13 @@ class AccompanyingPeriodWorkDenormalizer implements DenormalizerAwareInterface,
foreach ($kept as $k) {
$this->denormalizer->denormalize(
$dataById[$k->getId()],
AccompanyingPeriodWorkEvaluation::class,
AccompanyingPeriodWorkEvaluation::class,
$format,
\array_merge(
array_merge(
$context,
[
'groups' => [ 'write' ],
AbstractNormalizer::OBJECT_TO_POPULATE => $k
'groups' => ['write'],
AbstractNormalizer::OBJECT_TO_POPULATE => $k,
]
)
);
@@ -109,24 +115,12 @@ class AccompanyingPeriodWorkDenormalizer implements DenormalizerAwareInterface,
$newData,
AccompanyingPeriodWorkEvaluation::class,
$format,
\array_merge($context, ['groups' => [ 'accompanying_period_work_evaluation:create']]
array_merge(
$context,
['groups' => ['accompanying_period_work_evaluation:create']]
)
);
$work->addAccompanyingPeriodWorkEvaluation($evaluation);
}
}
/**
* @inheritDoc
*/
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
{
return $type === AccompanyingPeriodWork::class
&& ($context['skip'] ?? null) !== self::class
&& \is_array($data)
&& \array_key_exists("type", $data)
&& $data["type"] === 'accompanying_period_work';
}
}