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,23 +1,30 @@
<?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\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\MainBundle\Serializer\Normalizer\DiscriminatedObjectDenormalizer;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\AccompanyingPeriod\ResourceRepository;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
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\Normalizer\ObjectToPopulateTrait;
use Symfony\Component\Serializer\Exception;
use Chill\MainBundle\Serializer\Normalizer\DiscriminatedObjectDenormalizer;
use function array_key_exists;
use function array_merge;
class AccompanyingPeriodResourceNormalizer implements DenormalizerInterface, DenormalizerAwareInterface
{
use DenormalizerAwareTrait;
use ObjectToPopulateTrait;
private ResourceRepository $repository;
@@ -27,59 +34,57 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerInterface, Den
$this->repository = $repository;
}
public function denormalize($data, string $type, string $format = null, array $context = [])
public function denormalize($data, string $type, ?string $format = null, array $context = [])
{
$resource = $this->extractObjectToPopulate($type, $context);
if ('accompanying_period_resource' !== ($data['type'] ?? NULL)) {
if ('accompanying_period_resource' !== ($data['type'] ?? null)) {
throw new Exception\InvalidArgumentException("the key type must be present in data and set to 'accompanying_period_resource'");
}
if ($resource === NULL && \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']));
if (null === $resource) {
throw new Exception\UnexpectedValueException(sprintf('the resource with' .
'id %d is not found', $data['id']));
}
// if resource found, available only for read-only
if (count($data) > 2) {
unset($data['id']);
unset($data['type']);
unset($data['id'], $data['type']);
throw new Exception\ExtraAttributesException($data);
}
}
if ($resource === NULL) {
if (null === $resource) {
$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 =>
[
Person::class, ThirdParty::class
]
[
DiscriminatedObjectDenormalizer::ALLOWED_TYPES => [
Person::class, ThirdParty::class,
],
]
)
);
$resource->setResource($res);
}
}
return $resource;
}
public function supportsDenormalization($data, string $type, string $format = null)
public function supportsDenormalization($data, string $type, ?string $format = null)
{
return $type === Resource::class;
}
return Resource::class === $type;
}
}