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

api-platform / core / 14035635597

24 Mar 2025 12:46PM UTC coverage: 8.513% (-7.6%) from 16.086%
14035635597

push

github

web-flow
fix(laravel): defer "filters" dependent services (#7045)

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

3078 existing lines in 187 files now uncovered.

13386 of 157241 relevant lines covered (8.51%)

22.91 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
    {
30
    }
2,051✔
31

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

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

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

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

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

54
        return $resourceMetadataCollection;
135✔
55
    }
56

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

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

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

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

85
        return $operations;
128✔
86
    }
87

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

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

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

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

106
        return $attribute;
11✔
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