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

api-platform / core / 10557514433

26 Aug 2024 09:45AM UTC coverage: 7.704% (-0.003%) from 7.707%
10557514433

push

github

web-flow
feat(laravel): provide a trait in addition to the annotation (#6543)

* feat(laravel): provide a trait in addition to the annotation

* fix

* fix

* add support for ApiProperty and refactoring

* fix Eloquent property collection

* fix PHPStan

8 of 179 new or added lines in 11 files covered. (4.47%)

2 existing lines in 2 files now uncovered.

12489 of 162109 relevant lines covered (7.7%)

22.98 hits per line

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

0.0
/src/Laravel/Metadata/ConcernsResourceNameCollectionFactory.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\Laravel\Metadata;
15

16
use ApiPlatform\Laravel\IsApiResource;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
18
use ApiPlatform\Metadata\Resource\ResourceNameCollection;
19
use ApiPlatform\Metadata\Util\ReflectionClassRecursiveIterator;
20

21
/**
22
 * Creates a resource name collection from {@see IsApiResource} concerns.
23
 *
24
 * @author Kévin Dunglas <kevin@dunglas.dev>
25
 */
26
final class ConcernsResourceNameCollectionFactory implements ResourceNameCollectionFactoryInterface
27
{
28
    /**
29
     * @param string[] $paths
30
     */
31
    public function __construct(
32
        private readonly array $paths,
33
        private readonly ?ResourceNameCollectionFactoryInterface $decorated = null,
34
    ) {
NEW
35
    }
×
36

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

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

NEW
50
        foreach (ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories($this->paths) as $className => $reflectionClass) {
×
51
            if (
NEW
52
                $reflectionClass->hasMethod('apiResource')
×
NEW
53
                && ($m = $reflectionClass->getMethod('apiResource'))
×
NEW
54
                && $m->isPublic()
×
NEW
55
                && $m->isStatic()
×
56
            ) {
NEW
57
                $classes[$className] = true;
×
58
            }
59
        }
60

NEW
61
        return new ResourceNameCollection(array_keys($classes));
×
62
    }
63
}
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

© 2026 Coveralls, Inc