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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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
    }
708✔
35

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

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

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

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

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

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

UNCOV
68
        return false;
1✔
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