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

api-platform / core / 10508505187

22 Aug 2024 12:55PM UTC coverage: 7.704%. Remained the same
10508505187

push

github

soyuka
Merge 3.4

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

8840 existing lines in 284 files now uncovered.

12477 of 161949 relevant lines covered (7.7%)

22.99 hits per line

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

90.91
/src/Metadata/Resource/Factory/FiltersResourceMetadataCollectionFactory.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\Exception\ResourceClassNotFoundException;
17
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
18
use ApiPlatform\Metadata\Util\AttributeFilterExtractorTrait;
19

20
/**
21
 * Creates a resource metadata from {@see Resource} annotations.
22
 *
23
 * @author Antoine Bluchet <soyuka@gmail.com>
24
 */
25
final class FiltersResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
26
{
27
    use AttributeFilterExtractorTrait;
28

29
    public function __construct(private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null)
30
    {
UNCOV
31
    }
2,248✔
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function create(string $resourceClass): ResourceMetadataCollection
37
    {
UNCOV
38
        $resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
42✔
39

UNCOV
40
        if ($this->decorated) {
42✔
UNCOV
41
            $resourceMetadataCollection = $this->decorated->create($resourceClass);
42✔
42
        }
43

44
        try {
UNCOV
45
            $reflectionClass = new \ReflectionClass($resourceClass);
42✔
46
        } catch (\ReflectionException) {
×
47
            throw new ResourceClassNotFoundException(\sprintf('Resource "%s" not found.', $resourceClass));
×
48
        }
49

UNCOV
50
        $classFilters = $this->readFilterAttributes($reflectionClass);
42✔
UNCOV
51
        $filters = [];
42✔
52

UNCOV
53
        foreach ($classFilters as $id => [$args, $filterClass, $attribute]) {
42✔
UNCOV
54
            if (!$attribute->alias) {
17✔
UNCOV
55
                $filters[] = $id;
17✔
56
            }
57
        }
58

UNCOV
59
        foreach ($resourceMetadataCollection as $i => $resource) {
42✔
UNCOV
60
            foreach ($operations = $resource->getOperations() ?? [] as $operationName => $operation) {
34✔
UNCOV
61
                $operations->add($operationName, $operation->withFilters(array_unique(array_merge($resource->getFilters() ?? [], $operation->getFilters() ?? [], $filters))));
34✔
62
            }
63

UNCOV
64
            if ($operations) {
34✔
UNCOV
65
                $resourceMetadataCollection[$i] = $resource->withOperations($operations);
34✔
66
            }
67

UNCOV
68
            foreach ($graphQlOperations = $resource->getGraphQlOperations() ?? [] as $operationName => $operation) {
34✔
UNCOV
69
                $graphQlOperations[$operationName] = $operation->withFilters(array_unique(array_merge($resource->getFilters() ?? [], $operation->getFilters() ?? [], $filters)));
31✔
70
            }
71

UNCOV
72
            if ($graphQlOperations) {
34✔
UNCOV
73
                $resourceMetadataCollection[$i] = $resource->withGraphQlOperations($graphQlOperations);
31✔
74
            }
75
        }
76

UNCOV
77
        return $resourceMetadataCollection;
42✔
78
    }
79
}
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