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

api-platform / core / 15629538569

13 Jun 2025 07:58AM UTC coverage: 21.874% (-0.002%) from 21.876%
15629538569

Pull #7207

github

web-flow
Merge 3fb5fafc9 into cff61eab8
Pull Request #7207: feat(metadata) customize resource & operations

16 of 92 new or added lines in 9 files covered. (17.39%)

37 existing lines in 2 files now uncovered.

11410 of 52163 relevant lines covered (21.87%)

20.98 hits per line

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

60.0
/src/Metadata/Resource/Factory/CustomResourceMetadataCollectionFactory.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\Extractor\ClosureExtractorInterface;
17
use ApiPlatform\Metadata\Operations;
18
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
19

20
final class CustomResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
21
{
22
    use OperationDefaultsTrait;
23

24
    public function __construct(
25
        private readonly ClosureExtractorInterface $resourceClosureExtractor,
26
        private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null,
27
    ) {
28
    }
560✔
29

30
    public function create(string $resourceClass): ResourceMetadataCollection
31
    {
32
        $resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
96✔
33
        if ($this->decorated) {
96✔
34
            $resourceMetadataCollection = $this->decorated->create($resourceClass);
96✔
35
        }
36

37
        $newMetadataCollection = new ResourceMetadataCollection($resourceClass);
96✔
38

39
        foreach  ($resourceMetadataCollection as $resource) {
96✔
40
            foreach ($this->resourceClosureExtractor->getClosures() as  $closure) {
94✔
NEW
41
                $resource = $closure($resource);
×
42

NEW
43
                $operations = [];
×
NEW
44
                foreach ($resource->getOperations() as $operation) {
×
NEW
45
                    [$key, $operation] = $this->getOperationWithDefaults($resource, $operation);
×
NEW
46
                    $operations[$key] = $operation;
×
47
                }
48

NEW
49
                $resource = $resource->withOperations(new Operations($operations));
×
50
            }
51

52
            $newMetadataCollection[] = $resource;
94✔
53
        }
54

55
        return $newMetadataCollection;
96✔
56
    }
57
}
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