mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -25,7 +25,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Templating\Entity\ClosingMotiveRender;
|
||||
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
@@ -33,8 +32,6 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function is_array;
|
||||
|
||||
class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
@@ -43,15 +40,15 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
|
||||
private const PERIOD_NULL = [
|
||||
'id',
|
||||
'closingDate' => DateTime::class,
|
||||
'closingDate' => \DateTime::class,
|
||||
'closingMotive' => AccompanyingPeriod\ClosingMotive::class,
|
||||
'confidential',
|
||||
'confidentialText',
|
||||
'createdAt' => DateTime::class,
|
||||
'createdAt' => \DateTime::class,
|
||||
'createdBy' => User::class,
|
||||
'emergency',
|
||||
'emergencyText',
|
||||
'openingDate' => DateTime::class,
|
||||
'openingDate' => \DateTime::class,
|
||||
'origin' => AccompanyingPeriod\Origin::class,
|
||||
'originText',
|
||||
'requestorAnonymous',
|
||||
@@ -78,19 +75,19 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriod|null $period
|
||||
* @param string|null $format
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function normalize($period, $format = null, array $context = [])
|
||||
{
|
||||
if ($period instanceof AccompanyingPeriod) {
|
||||
$scopes = $this->scopeResolverDispatcher->isConcerned($period) ? $this->scopeResolverDispatcher->resolveScope($period) : [];
|
||||
|
||||
if (!is_array($scopes)) {
|
||||
if (!\is_array($scopes)) {
|
||||
$scopes = [$scopes];
|
||||
}
|
||||
|
||||
$addressContext = array_merge($context, ['docgen:expects' => Address::class, 'groups' => 'docgen:read']);
|
||||
$dateContext = array_merge($context, ['docgen:expects' => DateTime::class, 'groups' => 'docgen:read']);
|
||||
$dateContext = array_merge($context, ['docgen:expects' => \DateTime::class, 'groups' => 'docgen:read']);
|
||||
$userContext = array_merge($context, ['docgen:expects' => User::class, 'groups' => 'docgen:read']);
|
||||
$participationContext = array_merge($context, ['docgen:expects' => AccompanyingPeriodParticipation::class, 'groups' => 'docgen:read']);
|
||||
$administrativeLocationContext = array_merge($context, ['docgen:expects' => Location::class, 'groups' => 'docgen:read']);
|
||||
@@ -112,29 +109,29 @@ class AccompanyingPeriodDocGenNormalizer implements ContextAwareNormalizerInterf
|
||||
'currentParticipations' => $this->normalizer->normalize($period->getCurrentParticipations(), $format, $participationContext),
|
||||
'requestorAnonymous' => $period->isRequestorAnonymous(),
|
||||
'requestorPerson' => $this->normalizer->normalize($period->getRequestorPerson(), $format, array_merge($context, ['docgen:expects' => Person::class])),
|
||||
'hasRequestorPerson' => $period->getRequestorPerson() !== null,
|
||||
'hasRequestorPerson' => null !== $period->getRequestorPerson(),
|
||||
'requestorThirdParty' => $this->normalizer->normalize($period->getRequestorThirdParty(), $format, array_merge($context, ['docgen:expects' => ThirdParty::class])),
|
||||
'hasRequestorThirdParty' => $period->getRequestorThirdParty() !== null,
|
||||
'hasRequestorThirdParty' => null !== $period->getRequestorThirdParty(),
|
||||
'resources' => $this->normalizer->normalize($period->getResources(), $format, $context),
|
||||
'scopes' => $this->normalizer->normalize($scopes, $format, array_merge($context, ['docgen:expects' => Scope::class, 'groups' => 'docgen:read'])),
|
||||
'socialIssues' => $this->normalizer->normalize($period->getSocialIssues(), $format, $context),
|
||||
'intensity' => $this->translator->trans($period->getIntensity()),
|
||||
'step' => $this->translator->trans('accompanying_period.' . $period->getStep()),
|
||||
'step' => $this->translator->trans('accompanying_period.'.$period->getStep()),
|
||||
'emergencyText' => $period->isEmergency() ? $this->translator->trans('accompanying_period.emergency') : '',
|
||||
'confidentialText' => $period->isConfidential() ? $this->translator->trans('confidential') : '',
|
||||
'originText' => null !== $period->getOrigin() ? $this->translatableStringHelper->localize($period->getOrigin()->getLabel()) : '',
|
||||
'isClosed' => $period->getClosingDate() !== null,
|
||||
'isClosed' => null !== $period->getClosingDate(),
|
||||
'closingMotiveText' => null !== $period->getClosingMotive() ?
|
||||
$this->closingMotiveRender->renderString($period->getClosingMotive(), []) : '',
|
||||
'ref' => $this->normalizer->normalize($period->getUser(), $format, $userContext),
|
||||
'hasRef' => $period->getUser() !== null,
|
||||
'hasRef' => null !== $period->getUser(),
|
||||
'socialIssuesText' => implode(', ', array_map(fn (SocialIssue $s) => $this->socialIssueRender->renderString($s, []), $period->getSocialIssues()->toArray())),
|
||||
'scopesText' => implode(', ', array_map(fn (Scope $s) => $this->translatableStringHelper->localize($s->getName()), $scopes)),
|
||||
'hasRequestor' => $period->getRequestor() !== null,
|
||||
'hasRequestor' => null !== $period->getRequestor(),
|
||||
'requestorKind' => $period->getRequestorKind(),
|
||||
'hasLocation' => $period->getLocation() !== null,
|
||||
'hasLocationPerson' => $period->getPersonLocation() !== null,
|
||||
'hasAdministrativeLocation' => $period->getAdministrativeLocation() !== null,
|
||||
'hasLocation' => null !== $period->getLocation(),
|
||||
'hasLocationPerson' => null !== $period->getPersonLocation(),
|
||||
'hasAdministrativeLocation' => null !== $period->getAdministrativeLocation(),
|
||||
'locationPerson' => $this->normalizer->normalize($period->getPersonLocation(), $format, array_merge($context, ['docgen:expects' => Person::class])),
|
||||
'location' => $this->normalizer->normalize($period->getLocation(), $format, $addressContext),
|
||||
'administrativeLocation' => $this->normalizer->normalize($period->getAdministrativeLocation(), $format, $administrativeLocationContext),
|
||||
|
@@ -20,7 +20,7 @@ use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||
final class AccompanyingPeriodOriginNormalizer implements NormalizerInterface
|
||||
{
|
||||
/**
|
||||
* @param Origin $origin
|
||||
* @param Origin $origin
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function normalize($origin, $format = null, array $context = [])
|
||||
|
@@ -21,7 +21,7 @@ class AccompanyingPeriodParticipationNormalizer implements NormalizerAwareInterf
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriodParticipation $participation
|
||||
* @param string|null $format
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function normalize($participation, $format = null, array $context = [])
|
||||
{
|
||||
|
@@ -22,10 +22,6 @@ 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 count;
|
||||
|
||||
class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface, DenormalizerInterface
|
||||
{
|
||||
use DenormalizerAwareTrait;
|
||||
@@ -42,16 +38,15 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
|
||||
throw new Exception\InvalidArgumentException("the key type must be present in data and set to 'accompanying_period_resource'");
|
||||
}
|
||||
|
||||
if (null === $resource && array_key_exists('id', $data)) {
|
||||
if (null === $resource && \array_key_exists('id', $data)) {
|
||||
$resource = $this->repository->find($data['id']);
|
||||
|
||||
if (null === $resource) {
|
||||
throw new Exception\UnexpectedValueException(sprintf('the resource with' .
|
||||
'id %d is not found', $data['id']));
|
||||
throw new Exception\UnexpectedValueException(sprintf('the resource withid %d is not found', $data['id']));
|
||||
}
|
||||
|
||||
// if resource found, available only for read-only
|
||||
if (count($data) > 2) {
|
||||
if (\count($data) > 2) {
|
||||
unset($data['id'], $data['type']);
|
||||
|
||||
throw new Exception\ExtraAttributesException($data);
|
||||
@@ -62,12 +57,12 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
|
||||
$resource = new Resource();
|
||||
}
|
||||
|
||||
if (array_key_exists('resource', $data)) {
|
||||
if (\array_key_exists('resource', $data)) {
|
||||
$res = $this->denormalizer->denormalize(
|
||||
$data['resource'],
|
||||
DiscriminatedObjectDenormalizer::TYPE,
|
||||
$format,
|
||||
array_merge(
|
||||
\array_merge(
|
||||
$context,
|
||||
[
|
||||
DiscriminatedObjectDenormalizer::ALLOWED_TYPES => [
|
||||
@@ -80,7 +75,7 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
|
||||
$resource->setResource($res);
|
||||
}
|
||||
|
||||
if (array_key_exists('comment', $data)) {
|
||||
if (\array_key_exists('comment', $data)) {
|
||||
$resource->setComment($data['comment']);
|
||||
}
|
||||
|
||||
|
@@ -21,11 +21,6 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
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
|
||||
* add some logic for synchronizing collection.
|
||||
@@ -44,12 +39,12 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
|
||||
public function denormalize($data, $type, $format = null, array $context = [])
|
||||
{
|
||||
$work = $this->denormalizer->denormalize($data, $type, $format, array_merge(
|
||||
$work = $this->denormalizer->denormalize($data, $type, $format, \array_merge(
|
||||
$context,
|
||||
['skip' => self::class]
|
||||
));
|
||||
|
||||
if (in_array('accompanying_period_work:edit', $context['groups'] ?? [], true)) {
|
||||
if (\in_array('accompanying_period_work:edit', $context['groups'] ?? [], true)) {
|
||||
$this->handleEvaluationCollection($data, $work, $format, $context);
|
||||
}
|
||||
|
||||
@@ -60,8 +55,8 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
{
|
||||
return AccompanyingPeriodWork::class === $type
|
||||
&& self::class !== ($context['skip'] ?? null)
|
||||
&& is_array($data)
|
||||
&& array_key_exists('type', $data)
|
||||
&& \is_array($data)
|
||||
&& \array_key_exists('type', $data)
|
||||
&& 'accompanying_period_work' === $data['type'];
|
||||
}
|
||||
|
||||
@@ -71,7 +66,7 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
$dataWithoutId = [];
|
||||
|
||||
foreach ($data['accompanyingPeriodWorkEvaluations'] as $e) {
|
||||
if (array_key_exists('id', $e)) {
|
||||
if (\array_key_exists('id', $e)) {
|
||||
$dataById[$e['id']] = $e;
|
||||
} else {
|
||||
$dataWithoutId[] = $e;
|
||||
@@ -81,7 +76,7 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
// partition the separate kept evaluations and removed one
|
||||
[$kept, $removed] = $work->getAccompanyingPeriodWorkEvaluations()
|
||||
->partition(
|
||||
static fn (int $key, AccompanyingPeriodWorkEvaluation $a) => array_key_exists($a->getId(), $dataById)
|
||||
static fn (int $key, AccompanyingPeriodWorkEvaluation $a) => \array_key_exists($a->getId(), $dataById)
|
||||
);
|
||||
|
||||
// remove the evaluations from work
|
||||
@@ -94,7 +89,7 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
$dataById[$k->getId()],
|
||||
AccompanyingPeriodWorkEvaluation::class,
|
||||
$format,
|
||||
array_merge(
|
||||
\array_merge(
|
||||
$context,
|
||||
[
|
||||
'groups' => ['write'],
|
||||
@@ -109,7 +104,7 @@ class AccompanyingPeriodWorkDenormalizer implements ContextAwareDenormalizerInte
|
||||
$newData,
|
||||
AccompanyingPeriodWorkEvaluation::class,
|
||||
$format,
|
||||
array_merge(
|
||||
\array_merge(
|
||||
$context,
|
||||
['groups' => ['accompanying_period_work_evaluation:create']]
|
||||
)
|
||||
|
@@ -19,10 +19,6 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_merge;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* This denormalizer rely on AbstractNormalizer for most of the job, and
|
||||
* add some logic for synchronizing collection.
|
||||
@@ -35,7 +31,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
|
||||
|
||||
public function denormalize($data, $type, $format = null, array $context = [])
|
||||
{
|
||||
$evaluation = $this->denormalizer->denormalize($data, $type, $format, array_merge(
|
||||
$evaluation = $this->denormalizer->denormalize($data, $type, $format, \array_merge(
|
||||
$context,
|
||||
['skip' => self::class]
|
||||
));
|
||||
@@ -49,8 +45,8 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
|
||||
{
|
||||
return AccompanyingPeriodWorkEvaluation::class === $type
|
||||
&& self::class !== ($context['skip'] ?? null)
|
||||
&& is_array($data)
|
||||
&& array_key_exists('type', $data)
|
||||
&& \is_array($data)
|
||||
&& \array_key_exists('type', $data)
|
||||
&& 'accompanying_period_work_evaluation' === $data['type'];
|
||||
}
|
||||
|
||||
@@ -60,17 +56,17 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
|
||||
$dataWithoutId = [];
|
||||
|
||||
foreach ($data['documents'] as $e) {
|
||||
if (array_key_exists('id', $e)) {
|
||||
if (\array_key_exists('id', $e)) {
|
||||
$dataById[$e['id']] = $e;
|
||||
} else {
|
||||
$dataWithoutId[] = $e;
|
||||
}
|
||||
}
|
||||
|
||||
//partition the separate kept documents and removed one
|
||||
// partition the separate kept documents and removed one
|
||||
[$kept, $removed] = $evaluation->getDocuments()
|
||||
->partition(
|
||||
static fn (int $key, AccompanyingPeriodWorkEvaluationDocument $a) => array_key_exists($a->getId(), $dataById)
|
||||
static fn (int $key, AccompanyingPeriodWorkEvaluationDocument $a) => \array_key_exists($a->getId(), $dataById)
|
||||
);
|
||||
|
||||
// remove the document from evaluation
|
||||
@@ -84,7 +80,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
|
||||
$dataById[$k->getId()],
|
||||
AccompanyingPeriodWorkEvaluationDocument::class,
|
||||
$format,
|
||||
array_merge(
|
||||
\array_merge(
|
||||
$context,
|
||||
[
|
||||
'groups' => ['write'],
|
||||
@@ -99,7 +95,7 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements ContextAwareDenorm
|
||||
$newData,
|
||||
AccompanyingPeriodWorkEvaluationDocument::class,
|
||||
$format,
|
||||
array_merge(
|
||||
\array_merge(
|
||||
$context,
|
||||
['groups' => ['accompanying_period_work_evaluation:create']]
|
||||
)
|
||||
|
@@ -18,7 +18,6 @@ use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use function array_key_exists;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
@@ -28,7 +27,7 @@ class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements ContextAware
|
||||
|
||||
public function __construct(private readonly EntityWorkflowRepository $entityWorkflowRepository, private readonly MetadataExtractor $metadataExtractor, private readonly Registry $registry) {}
|
||||
|
||||
public function normalize($object, ?string $format = null, array $context = []): array
|
||||
public function normalize($object, string $format = null, array $context = []): array
|
||||
{
|
||||
$initial = $this->normalizer->normalize($object, $format, array_merge($context, [
|
||||
self::SKIP => spl_object_hash($object),
|
||||
@@ -48,12 +47,12 @@ class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements ContextAware
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = [])
|
||||
public function supportsNormalization($data, string $format = null, array $context = [])
|
||||
{
|
||||
return $data instanceof AccompanyingPeriodWorkEvaluationDocument
|
||||
&& 'json' === $format
|
||||
&& (
|
||||
!array_key_exists(self::SKIP, $context)
|
||||
!\array_key_exists(self::SKIP, $context)
|
||||
|| spl_object_hash($data) !== $context[self::SKIP]
|
||||
);
|
||||
}
|
||||
|
@@ -19,7 +19,6 @@ use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use function array_key_exists;
|
||||
|
||||
class AccompanyingPeriodWorkEvaluationNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
@@ -32,7 +31,7 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements ContextAwareNormaliz
|
||||
/**
|
||||
* @param AccompanyingPeriodWorkEvaluation $object
|
||||
*/
|
||||
public function normalize($object, ?string $format = null, array $context = []): array
|
||||
public function normalize($object, string $format = null, array $context = []): array
|
||||
{
|
||||
$initial = $this->normalizer->normalize($object, $format, array_merge(
|
||||
$context,
|
||||
@@ -65,10 +64,10 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements ContextAwareNormaliz
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
public function supportsNormalization($data, string $format = null, array $context = []): bool
|
||||
{
|
||||
return 'json' === $format
|
||||
&& $data instanceof AccompanyingPeriodWorkEvaluation
|
||||
&& !array_key_exists(self::IGNORE_EVALUATION, $context);
|
||||
&& !\array_key_exists(self::IGNORE_EVALUATION, $context);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use ArrayObject;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||
@@ -22,7 +21,6 @@ use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use function array_key_exists;
|
||||
|
||||
class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
@@ -37,7 +35,7 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac
|
||||
*
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
public function normalize($object, ?string $format = null, array $context = []): null|array|\ArrayObject|bool|float|int|string
|
||||
public function normalize($object, string $format = null, array $context = []): null|array|\ArrayObject|bool|float|int|string
|
||||
{
|
||||
$initial = $this->normalizer->normalize($object, $format, array_merge(
|
||||
$context,
|
||||
@@ -78,10 +76,10 @@ class AccompanyingPeriodWorkNormalizer implements ContextAwareNormalizerInterfac
|
||||
return $initial;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
public function supportsNormalization($data, string $format = null, array $context = []): bool
|
||||
{
|
||||
return 'json' === $format
|
||||
&& $data instanceof AccompanyingPeriodWork
|
||||
&& !array_key_exists(self::IGNORE_WORK, $context);
|
||||
&& !\array_key_exists(self::IGNORE_WORK, $context);
|
||||
}
|
||||
}
|
||||
|
@@ -18,15 +18,11 @@ 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 UnexpectedValueException;
|
||||
use function array_key_exists;
|
||||
|
||||
class MembersEditorNormalizer implements DenormalizerAwareInterface, DenormalizerInterface
|
||||
{
|
||||
use DenormalizerAwareTrait;
|
||||
@@ -66,7 +62,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
);
|
||||
$startDate = $this->denormalizer->denormalize(
|
||||
$concerned['start_date'] ?? null,
|
||||
DateTimeImmutable::class,
|
||||
\DateTimeImmutable::class,
|
||||
$format,
|
||||
$context
|
||||
);
|
||||
@@ -75,9 +71,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
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);
|
||||
@@ -112,7 +106,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
$context
|
||||
);
|
||||
|
||||
if (array_key_exists('position', $concerned)) {
|
||||
if (\array_key_exists('position', $concerned)) {
|
||||
$position = $this->denormalizer->denormalize(
|
||||
$concerned['position'] ?? null,
|
||||
Position::class,
|
||||
@@ -125,7 +119,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
|
||||
$startDate = $this->denormalizer->denormalize(
|
||||
$concerned['start_date'] ?? null,
|
||||
DateTimeImmutable::class,
|
||||
\DateTimeImmutable::class,
|
||||
$format,
|
||||
$context
|
||||
);
|
||||
@@ -138,9 +132,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
&& 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(
|
||||
@@ -155,10 +147,10 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
if (null !== $data['composition']) {
|
||||
$compositionType = $this->denormalizer->denormalize($data['composition']['household_composition_type'], HouseholdCompositionType::class, $format, $context);
|
||||
$numberOfChildren = $data['composition']['number_of_children'];
|
||||
$startDate = $this->denormalizer->denormalize($data['composition']['start_date'], DateTimeImmutable::class, $format, $context);
|
||||
$startDate = $this->denormalizer->denormalize($data['composition']['start_date'], \DateTimeImmutable::class, $format, $context);
|
||||
|
||||
if (null === $compositionType) {
|
||||
throw new UnexpectedValueException('composition type cannot be null');
|
||||
throw new \UnexpectedValueException('composition type cannot be null');
|
||||
}
|
||||
|
||||
$householdComposition = (new HouseholdComposition())
|
||||
@@ -181,7 +173,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
|
||||
throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'");
|
||||
}
|
||||
|
||||
if (false === array_key_exists('destination', $data)) {
|
||||
if (false === \array_key_exists('destination', $data)) {
|
||||
throw new Exception\UnexpectedValueException("The schema does not have any key 'destination'");
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Repository\Relationships\RelationshipRepository;
|
||||
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\DataFixtures\Exception\CircularReferenceException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
@@ -33,12 +32,6 @@ use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
use function array_map;
|
||||
use function implode;
|
||||
use function in_array;
|
||||
use function is_string;
|
||||
|
||||
class PersonDocGenNormalizer implements
|
||||
ContextAwareNormalizerInterface,
|
||||
NormalizerAwareInterface
|
||||
@@ -63,7 +56,7 @@ class PersonDocGenNormalizer implements
|
||||
|
||||
/** @var Person $person */
|
||||
$dateContext = $context;
|
||||
$dateContext['docgen:expects'] = DateTimeInterface::class;
|
||||
$dateContext['docgen:expects'] = \DateTimeInterface::class;
|
||||
$addressContext = array_merge($context, ['docgen:expects' => Address::class]);
|
||||
$phonenumberContext = array_merge($context, ['docgen:expects' => PhoneNumber::class]);
|
||||
$centerContext = array_merge($context, ['docgen:expects' => Center::class]);
|
||||
@@ -90,9 +83,9 @@ class PersonDocGenNormalizer implements
|
||||
'civility' => $this->normalizer->normalize($person->getCivility(), $format, array_merge($context, ['docgen:expects' => Civility::class])),
|
||||
'firstName' => $person->getFirstName(),
|
||||
'lastName' => $person->getLastName(),
|
||||
'altNames' => implode(
|
||||
'altNames' => \implode(
|
||||
', ',
|
||||
array_map(
|
||||
\array_map(
|
||||
static fn (PersonAltName $altName) => $altName->getLabel(),
|
||||
$person->getAltNames()->toArray()
|
||||
)
|
||||
@@ -177,7 +170,7 @@ class PersonDocGenNormalizer implements
|
||||
$key = spl_object_hash($person);
|
||||
}
|
||||
|
||||
if (!array_key_exists(self::CIRCULAR_KEY, $context)) {
|
||||
if (!\array_key_exists(self::CIRCULAR_KEY, $context)) {
|
||||
$context[self::CIRCULAR_KEY] = [$key];
|
||||
|
||||
return $context;
|
||||
@@ -204,11 +197,11 @@ class PersonDocGenNormalizer implements
|
||||
{
|
||||
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
|
||||
|
||||
if (is_string($groups)) {
|
||||
if (\is_string($groups)) {
|
||||
$groups = [$groups];
|
||||
}
|
||||
|
||||
return in_array($group, $groups, true);
|
||||
return \in_array($group, $groups, true);
|
||||
}
|
||||
|
||||
private function normalizeNullValue(string $format, array $context)
|
||||
@@ -219,10 +212,10 @@ class PersonDocGenNormalizer implements
|
||||
'id', 'firstName', 'lastName', 'age', 'altNames', 'text',
|
||||
'center' => Center::class,
|
||||
'civility' => Civility::class,
|
||||
'birthdate' => DateTimeInterface::class,
|
||||
'deathdate' => DateTimeInterface::class,
|
||||
'birthdate' => \DateTimeInterface::class,
|
||||
'deathdate' => \DateTimeInterface::class,
|
||||
'gender', 'maritalStatus',
|
||||
'maritalStatusDate' => DateTimeInterface::class,
|
||||
'maritalStatusDate' => \DateTimeInterface::class,
|
||||
'maritalStatusComment',
|
||||
'email', 'firstPhoneNumber', 'fixPhoneNumber', 'mobilePhoneNumber', 'nationality',
|
||||
'placeOfBirth', 'memo', 'numberOfChildren',
|
||||
|
@@ -20,8 +20,6 @@ use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use Chill\PersonBundle\Repository\ResidentialAddressRepository;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
@@ -31,10 +29,6 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
|
||||
use function array_key_exists;
|
||||
use function count;
|
||||
use function in_array;
|
||||
use function is_string;
|
||||
|
||||
/**
|
||||
* Serialize a Person entity.
|
||||
@@ -60,13 +54,13 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
||||
{
|
||||
$person = $this->extractObjectToPopulate($type, $context);
|
||||
|
||||
if (array_key_exists('id', $data) && null === $person) {
|
||||
if (\array_key_exists('id', $data) && null === $person) {
|
||||
$person = $this->repository->find($data['id']);
|
||||
|
||||
if (null === $person) {
|
||||
throw new UnexpectedValueException("The person with id \"{$data['id']}\" does " .
|
||||
'not exists');
|
||||
throw new UnexpectedValueException("The person with id \"{$data['id']}\" does ".'not exists');
|
||||
}
|
||||
|
||||
// currently, not allowed to update a person through api
|
||||
// if instantiated with id
|
||||
return $person;
|
||||
@@ -92,7 +86,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
||||
|
||||
$fields = array_filter(
|
||||
$fields,
|
||||
static fn (string $field): bool => array_key_exists($field, $data)
|
||||
static fn (string $field): bool => \array_key_exists($field, $data)
|
||||
);
|
||||
|
||||
foreach ($fields as $item) {
|
||||
@@ -123,14 +117,14 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
||||
break;
|
||||
|
||||
case 'birthdate':
|
||||
$object = $this->denormalizer->denormalize($data[$item], DateTime::class, $format, $context);
|
||||
$object = $this->denormalizer->denormalize($data[$item], \DateTime::class, $format, $context);
|
||||
|
||||
$person->setBirthdate($object);
|
||||
|
||||
break;
|
||||
|
||||
case 'deathdate':
|
||||
$object = $this->denormalizer->denormalize($data[$item], DateTimeImmutable::class, $format, $context);
|
||||
$object = $this->denormalizer->denormalize($data[$item], \DateTimeImmutable::class, $format, $context);
|
||||
|
||||
$person->setDeathdate($object);
|
||||
|
||||
@@ -178,14 +172,14 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Person $person
|
||||
* @param Person $person
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function normalize($person, $format = null, array $context = [])
|
||||
{
|
||||
$groups = $context[AbstractNormalizer::GROUPS] ?? [];
|
||||
|
||||
if (is_string($groups)) {
|
||||
if (\is_string($groups)) {
|
||||
$groups = [$groups];
|
||||
}
|
||||
$household = $person->getCurrentHousehold();
|
||||
@@ -209,7 +203,7 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
|
||||
'civility' => $this->normalizer->normalize($person->getCivility(), $format, $context),
|
||||
];
|
||||
|
||||
if (in_array('minimal', $groups, true) && 1 === count($groups)) {
|
||||
if (\in_array('minimal', $groups, true) && 1 === \count($groups)) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,7 @@ class RelationshipDocGenNormalizer implements ContextAwareNormalizerInterface, N
|
||||
|
||||
/**
|
||||
* @param Relationship $relation
|
||||
* @param string|null $format
|
||||
* @param string|null $format
|
||||
*/
|
||||
public function normalize($relation, $format = null, array $context = [])
|
||||
{
|
||||
|
@@ -25,7 +25,7 @@ class SocialIssueNormalizer implements ContextAwareNormalizerInterface, Normaliz
|
||||
|
||||
public function normalize($socialIssue, $format = null, array $context = [])
|
||||
{
|
||||
/** @var SocialIssue $socialIssue */
|
||||
/* @var SocialIssue $socialIssue */
|
||||
switch ($format) {
|
||||
case 'json':
|
||||
return [
|
||||
|
@@ -11,7 +11,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
|
||||
use ArrayObject;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Workflow\Helper\MetadataExtractor;
|
||||
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||
@@ -19,7 +18,6 @@ use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use function array_key_exists;
|
||||
|
||||
class WorkflowNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
@@ -32,11 +30,11 @@ class WorkflowNormalizer implements ContextAwareNormalizerInterface, NormalizerA
|
||||
/**
|
||||
* @param EntityWorkflow $object
|
||||
*
|
||||
* @throws ExceptionInterface
|
||||
* @return array|\ArrayObject|bool|float|int|string|void|null
|
||||
*
|
||||
* @return array|ArrayObject|bool|float|int|string|void|null
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
public function normalize($object, ?string $format = null, array $context = []): array
|
||||
public function normalize($object, string $format = null, array $context = []): array
|
||||
{
|
||||
$data = $this->normalizer->normalize($object, $format, array_merge(
|
||||
$context,
|
||||
@@ -53,10 +51,10 @@ class WorkflowNormalizer implements ContextAwareNormalizerInterface, NormalizerA
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
public function supportsNormalization($data, string $format = null, array $context = []): bool
|
||||
{
|
||||
return 'json' === $format
|
||||
&& $data instanceof EntityWorkflow
|
||||
&& !array_key_exists(self::IGNORE_ENTITY_WORKFLOW, $context);
|
||||
&& !\array_key_exists(self::IGNORE_ENTITY_WORKFLOW, $context);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user