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,14 +1,21 @@
<?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\MainBundle\Serializer\Normalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Doctrine\ORM\Mapping\ClassMetadata;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface as SerializerMetadata;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use function array_key_exists;
use function is_array;
class DoctrineExistingEntityNormalizer implements DenormalizerInterface
{
@@ -16,16 +23,15 @@ class DoctrineExistingEntityNormalizer implements DenormalizerInterface
private ClassMetadataFactoryInterface $serializerMetadataFactory;
public function __construct(EntityManagerInterface $em, ClassMetadataFactoryInterface $serializerMetadataFactory)
{
$this->em = $em;
$this->serializerMetadataFactory = $serializerMetadataFactory;
}
public function denormalize($data, string $type, string $format = null, array $context = [])
public function denormalize($data, string $type, ?string $format = null, array $context = [])
{
if (\array_key_exists(AbstractNormalizer::OBJECT_TO_POPULATE, $context)) {
if (array_key_exists(AbstractNormalizer::OBJECT_TO_POPULATE, $context)) {
return $context[AbstractNormalizer::OBJECT_TO_POPULATE];
}
@@ -33,23 +39,22 @@ class DoctrineExistingEntityNormalizer implements DenormalizerInterface
->find($data['id']);
}
public function supportsDenormalization($data, string $type, string $format = null)
public function supportsDenormalization($data, string $type, ?string $format = null)
{
if (FALSE === \is_array($data)) {
if (false === is_array($data)) {
return false;
}
if (FALSE === \array_key_exists('id', $data)) {
if (false === array_key_exists('id', $data)) {
return false;
}
}
if (FALSE === $this->em->getClassMetadata($type) instanceof ClassMetadata) {
return false;
if (false === $this->em->getClassMetadata($type) instanceof ClassMetadata) {
return false;
}
// does have serializer metadata, and class discriminator ?
if ($this->serializerMetadataFactory->hasMetadataFor($type)) {
$classDiscriminator = $this->serializerMetadataFactory
->getMetadataFor($type)->getClassDiscriminatorMapping();
@@ -58,14 +63,14 @@ class DoctrineExistingEntityNormalizer implements DenormalizerInterface
// check that only 2 keys
// that the second key is property
// and that the type match the class for given type property
// and that the type match the class for given type property
return count($data) === 2
&& \array_key_exists($typeProperty, $data)
&& $type === $classDiscriminator->getClassForType($data[$typeProperty]);
&& array_key_exists($typeProperty, $data)
&& $classDiscriminator->getClassForType($data[$typeProperty]) === $type;
}
}
// we do not have any class discriminator. Check that the id is the only one key
return count($data) === 1;
}
}
}