Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
CRAP
83.33% covered (warning)
83.33%
10 / 12
SerializerExtractor
0.00% covered (danger)
0.00%
0 / 1
50.00% covered (danger)
50.00%
1 / 2
8.30
83.33% covered (warning)
83.33%
10 / 12
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getProperties
0.00% covered (danger)
0.00%
0 / 1
7.39
80.00% covered (warning)
80.00%
8 / 10
<?php
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Symfony\Component\PropertyInfo\Extractor;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
/**
 * Lists available properties using Symfony Serializer Component metadata.
 *
 * @author K√©vin Dunglas <dunglas@gmail.com>
 *
 * @final
 */
class SerializerExtractor implements PropertyListExtractorInterface
{
    private $classMetadataFactory;
    public function __construct(ClassMetadataFactoryInterface $classMetadataFactory)
    {
        $this->classMetadataFactory = $classMetadataFactory;
    }
    /**
     * {@inheritdoc}
     */
    public function getProperties(string $class, array $context = []): ?array
    {
        if (!isset($context['serializer_groups']) || !\is_array($context['serializer_groups'])) {
            return null;
        }
        if (!$this->classMetadataFactory->getMetadataFor($class)) {
            return null;
        }
        $properties = [];
        $serializerClassMetadata = $this->classMetadataFactory->getMetadataFor($class);
        foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
            if (array_intersect($context['serializer_groups'], $serializerAttributeMetadata->getGroups())) {
                $properties[] = $serializerAttributeMetadata->getName();
            }
        }
        return $properties;
    }
}