mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-02-01 05:57:16 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user