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

api-platform / core / 15276908793

27 May 2025 01:41PM UTC coverage: 26.397% (+4.7%) from 21.714%
15276908793

push

github

web-flow
chore: type-info v7.3.0-RC1 #7177 (#7178)

13727 of 52003 relevant lines covered (26.4%)

72.72 hits per line

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

100.0
/src/Metadata/Resource/Factory/AttributesResourceNameCollectionFactory.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\Resource\Factory;
15

16
use ApiPlatform\Metadata\ApiResource;
17
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Resource\ResourceNameCollection;
20
use ApiPlatform\Metadata\Util\ReflectionClassRecursiveIterator;
21

22
/**
23
 * Creates a resource name collection from {@see ApiResource} annotations.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class AttributesResourceNameCollectionFactory implements ResourceNameCollectionFactoryInterface
28
{
29
    /**
30
     * @param string[] $paths
31
     */
32
    public function __construct(private readonly array $paths, private readonly ?ResourceNameCollectionFactoryInterface $decorated = null)
33
    {
34
    }
1,552✔
35

36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function create(): ResourceNameCollection
40
    {
41
        $classes = [];
2✔
42

43
        if ($this->decorated) {
2✔
44
            foreach ($this->decorated->create() as $resourceClass) {
2✔
45
                $classes[$resourceClass] = true;
2✔
46
            }
47
        }
48

49
        foreach (ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories($this->paths) as $className => $reflectionClass) {
2✔
50
            if ($this->isResource($reflectionClass)) {
2✔
51
                $classes[$className] = true;
2✔
52
            }
53
        }
54

55
        return new ResourceNameCollection(array_keys($classes));
2✔
56
    }
57

58
    private function isResource(\ReflectionClass $reflectionClass): bool
59
    {
60
        if ($reflectionClass->getAttributes(ApiResource::class, \ReflectionAttribute::IS_INSTANCEOF)) {
2✔
61
            return true;
2✔
62
        }
63

64
        if ($reflectionClass->getAttributes(HttpOperation::class, \ReflectionAttribute::IS_INSTANCEOF) || $reflectionClass->getAttributes(GraphQlOperation::class, \ReflectionAttribute::IS_INSTANCEOF)) {
2✔
65
            return true;
2✔
66
        }
67

68
        return false;
2✔
69
    }
70
}
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