• 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/InputOutputResourceMetadataCollectionFactory.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\HttpOperation;
18
use ApiPlatform\Metadata\Operations;
19
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
20

21
/**
22
 * Transforms the given input/output metadata to a normalized one.
23
 *
24
 * @author Antoine Bluchet <soyuka@gmail.com>
25
 */
26
final class InputOutputResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
27
{
28
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $decorated)
29
    {
UNCOV
30
    }
978✔
31

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

UNCOV
39
        foreach ($resourceMetadataCollection as $key => $resourceMetadata) {
69✔
UNCOV
40
            $resourceMetadata = $resourceMetadata->withInput($this->transformInputOutput($resourceMetadata->getInput()));
65✔
UNCOV
41
            $resourceMetadata = $resourceMetadata->withOutput($this->transformInputOutput($resourceMetadata->getOutput()));
65✔
42

UNCOV
43
            if ($resourceMetadata->getOperations()) {
65✔
UNCOV
44
                $resourceMetadata = $resourceMetadata->withOperations($this->getTransformedOperations($resourceMetadata->getOperations(), $resourceMetadata));
65✔
45
            }
46

UNCOV
47
            if ($resourceMetadata->getGraphQlOperations()) {
65✔
UNCOV
48
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($this->getTransformedOperations($resourceMetadata->getGraphQlOperations(), $resourceMetadata));
53✔
49
            }
50

UNCOV
51
            $resourceMetadataCollection[$key] = $resourceMetadata;
65✔
52
        }
53

UNCOV
54
        return $resourceMetadataCollection;
69✔
55
    }
56

57
    private function getTransformedOperations(Operations|array $operations, ApiResource $resourceMetadata): Operations|array
58
    {
UNCOV
59
        foreach ($operations as $key => $operation) {
65✔
UNCOV
60
            $operation = $operation->withInput(null !== $operation->getInput() ? $this->transformInputOutput($operation->getInput()) : $resourceMetadata->getInput());
65✔
UNCOV
61
            $operation = $operation->withOutput(null !== $operation->getOutput() ? $this->transformInputOutput($operation->getOutput()) : $resourceMetadata->getOutput());
65✔
62

63
            if (
UNCOV
64
                $operation->getInput()
65✔
UNCOV
65
                && \array_key_exists('class', $operation->getInput())
65✔
UNCOV
66
                && null === $operation->getInput()['class']
65✔
67
            ) {
68
                $operation = $operation->withDeserialize(null === $operation->canDeserialize() ? false : $operation->canDeserialize());
1✔
69
                $operation = $operation->withValidate(null === $operation->canValidate() ? false : $operation->canValidate());
1✔
70
            }
71

72
            if (
UNCOV
73
                $operation instanceof HttpOperation
65✔
UNCOV
74
                && $operation->getOutput()
65✔
UNCOV
75
                && \array_key_exists('class', $operation->getOutput())
65✔
UNCOV
76
                && null === $operation->getOutput()['class']
65✔
UNCOV
77
                && null === $operation->getStatus()
65✔
78
            ) {
79
                $operation = $operation->withStatus(204);
1✔
80
            }
81

UNCOV
82
            $operations instanceof Operations ? $operations->add($key, $operation) : $operations[$key] = $operation;
65✔
83
        }
84

UNCOV
85
        return $operations;
65✔
86
    }
87

88
    private function transformInputOutput(mixed $attribute): ?array
89
    {
UNCOV
90
        if (false === $attribute) {
65✔
UNCOV
91
            return ['class' => null];
20✔
92
        }
93

UNCOV
94
        if (!$attribute) {
65✔
UNCOV
95
            return null;
65✔
96
        }
97

UNCOV
98
        if (\is_string($attribute)) {
5✔
UNCOV
99
            $attribute = ['class' => $attribute];
5✔
100
        }
101

UNCOV
102
        if (!isset($attribute['name']) && isset($attribute['class'])) {
5✔
UNCOV
103
            $attribute['name'] = (new \ReflectionClass($attribute['class']))->getShortName();
5✔
104
        }
105

UNCOV
106
        return $attribute;
5✔
107
    }
108
}
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