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

api-platform / core / 15927526370

27 Jun 2025 01:30PM UTC coverage: 22.016% (-0.008%) from 22.024%
15927526370

push

github

web-flow
refactor(metadata): cascade resource to operation (#7246)

12 of 46 new or added lines in 12 files covered. (26.09%)

63 existing lines in 2 files now uncovered.

11494 of 52207 relevant lines covered (22.02%)

21.67 hits per line

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

0.0
/src/Metadata/CascadeToOperationsTrait.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;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
18

19
/**
20
 * @internal
21
 *
22
 * @phpstan-require-extends ApiResource
23
 */
24
trait CascadeToOperationsTrait
25
{
26
    public function cascadeToOperations(): static
27
    {
NEW
28
        if (!$this instanceof ApiResource) {
×
NEW
29
            throw new RuntimeException('Not an API resource');
×
30
        }
31

NEW
32
        if (!($operations = $this->getOperations() ?? [])) {
×
NEW
33
            return $this;
×
34
        }
35

NEW
36
        return (clone $this)->withOperations(
×
NEW
37
            new Operations($this->getMutatedOperations($operations, $this)),
×
NEW
38
        );
×
39
    }
40

41
    public function cascadeToGraphQlOperations(): static
42
    {
NEW
43
        if (!$this instanceof ApiResource) {
×
NEW
44
            throw new RuntimeException('Not an API resource');
×
45
        }
46

NEW
47
        if (!($operations = $this->getGraphQlOperations() ?? [])) {
×
NEW
48
            return $this;
×
49
        }
50

NEW
51
        return (clone $this)->withGraphQlOperations(
×
NEW
52
            $this->getMutatedOperations($operations, $this),
×
NEW
53
        );
×
54
    }
55

56
    /**
57
     * @param Operations<HttpOperation>|list<GraphQlOperation> $operations
58
     *
59
     * @return array[string, HttpOperation]|list<GraphQlOperation>
60
     */
61
    private function getMutatedOperations(iterable $operations, ApiResource $apiResource): iterable
62
    {
NEW
63
        $modifiedOperations = [];
×
NEW
64
        foreach ($operations as $key => $operation) {
×
NEW
65
            $modifiedOperations[$key] = $operation->cascadeFromResource($apiResource);
×
66
        }
67

NEW
68
        return $modifiedOperations;
×
69
    }
70
}
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