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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 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
    }
978✔
32

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

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

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

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

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

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

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

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

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

UNCOV
77
        return $resourceMetadataCollection;
69✔
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