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

api-platform / core / 13740694161

08 Mar 2025 07:15PM UTC coverage: 8.521% (+0.002%) from 8.519%
13740694161

Pull #7008

github

web-flow
Merge 66ffb4082 into 7806e8523
Pull Request #7008: feat(httpcache): add more cache directives to AddHeadersProcessor

0 of 46 new or added lines in 2 files covered. (0.0%)

9932 existing lines in 306 files now uncovered.

13382 of 157041 relevant lines covered (8.52%)

22.92 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
    {
UNCOV
34
    }
1,553✔
35

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

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

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

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

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

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

UNCOV
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