• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 15256141101

26 May 2025 02:16PM UTC coverage: 21.714% (-4.8%) from 26.526%
15256141101

push

github

web-flow
Merge 4.1

6 of 387 new or added lines in 28 files covered. (1.55%)

1891 existing lines in 117 files now uncovered.

11118 of 51201 relevant lines covered (21.71%)

29.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Metadata/Property/Factory/ClassLevelAttributePropertyNameCollectionFactory.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Metadata\Property\Factory;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\Property\PropertyNameCollection;
18

19
/**
20
 * Gathers "virtual" properties created using the ApiProperty attribute at class level.
21
 */
22
final class ClassLevelAttributePropertyNameCollectionFactory implements PropertyNameCollectionFactoryInterface
23
{
24
    public function __construct(
25
        private readonly ?PropertyNameCollectionFactoryInterface $decorated = null,
26
    ) {
27
    }
×
28

29
    public function create(string $resourceClass, array $options = []): PropertyNameCollection
30
    {
31
        $parentPropertyNameCollection = $this->decorated?->create($resourceClass, $options);
×
32
        if (!class_exists($resourceClass)) {
×
33
            return $parentPropertyNameCollection ?? new PropertyNameCollection();
×
34
        }
35

NEW
36
        $properties = $parentPropertyNameCollection ? array_flip(iterator_to_array($parentPropertyNameCollection)) : [];
×
37

38
        $refl = new \ReflectionClass($resourceClass);
×
39
        $attributes = $refl->getAttributes(ApiProperty::class);
×
40
        foreach ($attributes as $attribute) {
×
41
            $instance = $attribute->newInstance();
×
42
            if ($property = $instance->getProperty()) {
×
NEW
43
                $properties[$property] = true;
×
44
            }
45
        }
46

NEW
47
        return new PropertyNameCollection(array_keys($properties));
×
48
    }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc