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

api-platform / core / 13718525764

07 Mar 2025 10:15AM UTC coverage: 7.289%. Remained the same
13718525764

push

github

web-flow
fix(doctrine): Add a proper exception when a doctrine manager could not be found for a resource class (#6995)

* fix(doctrine): Add a proper exception when a doctrine manager could not be found for a resource class

* Update ItemProvider.php

---------

Co-authored-by: Antoine Bluchet <soyuka@users.noreply.github.com>

1 of 2 new or added lines in 1 file covered. (50.0%)

2387 existing lines in 157 files now uncovered.

12437 of 170624 relevant lines covered (7.29%)

11.99 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
    }
709✔
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