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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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
    }
1,214✔
31

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

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

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

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

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

54
        return $resourceMetadataCollection;
101✔
55
    }
56

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

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

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

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

85
        return $operations;
96✔
86
    }
87

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

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

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

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

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