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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 hits per line

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

92.86
/src/Metadata/Resource/Factory/LinkResourceMetadataCollectionFactory.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\Link;
17
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
18

19
/**
20
 * Prepares graphql links.
21
 *
22
 * @author Alan Poulain <contact@alanpoulain.eu>
23
 */
24
final class LinkResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
25
{
26
    public function __construct(private readonly LinkFactoryInterface $linkFactory, private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null, private bool $graphQlEnabled = false)
27
    {
UNCOV
28
    }
291✔
29

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

UNCOV
40
        if (!$this->graphQlEnabled) {
50✔
41
            return $resourceMetadataCollection;
×
42
        }
43

UNCOV
44
        foreach ($resourceMetadataCollection as $i => $resource) {
50✔
UNCOV
45
            $graphQlOperations = [];
49✔
UNCOV
46
            foreach ($resource->getGraphQlOperations() ?? [] as $graphQlOperation) {
49✔
UNCOV
47
                $relationLinks = $this->linkFactory->createLinksFromRelations($graphQlOperation);
36✔
UNCOV
48
                $attributeLinks = $this->linkFactory->createLinksFromAttributes($graphQlOperation);
36✔
UNCOV
49
                $links = [];
36✔
UNCOV
50
                foreach ($attributeLinks as $link) {
36✔
UNCOV
51
                    $links[] = $this->linkFactory->completeLink($link);
1✔
52
                }
UNCOV
53
                $links = $this->mergeLinks($relationLinks, $links);
36✔
54

UNCOV
55
                $graphQlOperations[$graphQlOperation->getName()] = $graphQlOperation->withLinks($links);
36✔
56
            }
57

UNCOV
58
            $resource = $resource->withGraphQlOperations($graphQlOperations);
49✔
UNCOV
59
            $resourceMetadataCollection[$i] = $resource;
49✔
60
        }
61

UNCOV
62
        return $resourceMetadataCollection;
50✔
63
    }
64

65
    /**
66
     * @param Link[] $links
67
     * @param Link[] $toMergeLinks
68
     *
69
     * @return Link[]
70
     */
71
    private function mergeLinks(array $links, array $toMergeLinks): array
72
    {
UNCOV
73
        $classLinks = [];
36✔
UNCOV
74
        foreach ($links as $link) {
36✔
UNCOV
75
            $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $link;
12✔
76
        }
77

UNCOV
78
        foreach ($toMergeLinks as $link) {
36✔
UNCOV
79
            if (null !== $prevLink = $classLinks[$link->getToClass().'#'.$link->getFromProperty()] ?? null) {
1✔
UNCOV
80
                $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $prevLink->withLink($link);
1✔
81

UNCOV
82
                continue;
1✔
83
            }
84
            $classLinks[$link->getToClass().'#'.$link->getFromProperty()] = $link;
×
85
        }
86

UNCOV
87
        return array_values($classLinks);
36✔
88
    }
89
}
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