• 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

100.0
/src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.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\CollectionOperationInterface;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\NotExposed;
20
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
21

22
/**
23
 * Adds a {@see ApiPlatform\Metadata\NotExposed} operation with {@see ApiPlatform\Symfony\Action\NotFoundAction} on a resource which only has a GetCollection.
24
 * This operation helps to generate resource IRI for items.
25
 *
26
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
27
 */
28
final class NotExposedOperationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
29
{
30
    use OperationDefaultsTrait;
31

32
    public static $skolemUriTemplate = '/.well-known/genid/{id}';
33

34
    private $linkFactory;
35
    private $decorated;
36

37
    public function __construct(LinkFactoryInterface $linkFactory, ?ResourceMetadataCollectionFactoryInterface $decorated = null)
38
    {
UNCOV
39
        $this->linkFactory = $linkFactory;
978✔
UNCOV
40
        $this->decorated = $decorated;
978✔
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function create(string $resourceClass): ResourceMetadataCollection
47
    {
UNCOV
48
        $resourceMetadataCollection = new ResourceMetadataCollection($resourceClass);
69✔
UNCOV
49
        if ($this->decorated) {
69✔
UNCOV
50
            $resourceMetadataCollection = $this->decorated->create($resourceClass);
69✔
51
        }
52

53
        // Do not add a NotExposed operation on a resourceClass with no resource
UNCOV
54
        if (!$resourceMetadataCollection->count()) {
69✔
UNCOV
55
            return $resourceMetadataCollection;
4✔
56
        }
57

58
        /** @var ApiResource $resource */
UNCOV
59
        foreach ($resourceMetadataCollection as $resource) {
65✔
UNCOV
60
            $operations = $resource->getOperations();
65✔
61

62
            /** @var HttpOperation $operation */
UNCOV
63
            foreach ($operations as $operation) {
65✔
64
                // An item operation has been found, nothing to do anymore in this factory
UNCOV
65
                if (('GET' === $operation->getMethod() && !$operation instanceof CollectionOperationInterface) || ($operation->getExtraProperties()['is_legacy_resource_metadata'] ?? false)) {
65✔
UNCOV
66
                    return $resourceMetadataCollection;
50✔
67
                }
68
            }
69
        }
70

71
        // No item operation has been found on all resources for resource class: generate one on the last resource
72
        // Helpful to generate an IRI for a resource without declaring the Get operation
73
        /** @var HttpOperation $operation */
UNCOV
74
        [$key, $operation] = $this->getOperationWithDefaults(resource: $resource, operation: new NotExposed(), generated: true, ignoredOptions: ['uriTemplate', 'uriVariables']); // @phpstan-ignore-line $resource is defined if count > 0
19✔
75

UNCOV
76
        if (!$this->linkFactory->createLinksFromIdentifiers($operation)) {
19✔
UNCOV
77
            $operation = $operation->withUriTemplate(self::$skolemUriTemplate);
6✔
78
        }
79

UNCOV
80
        $operations->add($key, $operation)->sort(); // @phpstan-ignore-line $operation exists
19✔
81

UNCOV
82
        return $resourceMetadataCollection;
19✔
83
    }
84
}
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