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

api-platform / core / 14408211113

11 Apr 2025 04:58PM UTC coverage: 61.931% (+0.9%) from 61.025%
14408211113

Pull #7085

github

web-flow
Merge 2461e799a into c5fb664d1
Pull Request #7085: [fix] inverse ternary operator statements

1 of 1 new or added line in 1 file covered. (100.0%)

168 existing lines in 28 files now uncovered.

11482 of 18540 relevant lines covered (61.93%)

68.58 hits per line

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

4.55
/src/GraphQl/Resolver/Factory/ItemSubscriptionResolverFactory.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\GraphQl\Resolver\Factory;
15

16
use ApiPlatform\GraphQl\Resolver\Stage\ReadStageInterface;
17
use ApiPlatform\GraphQl\Resolver\Stage\SecurityStageInterface;
18
use ApiPlatform\GraphQl\Resolver\Stage\SerializeStageInterface;
19
use ApiPlatform\GraphQl\Subscription\MercureSubscriptionIriGeneratorInterface;
20
use ApiPlatform\GraphQl\Subscription\SubscriptionManagerInterface;
21
use ApiPlatform\Metadata\GraphQl\Operation;
22
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
23
use ApiPlatform\Metadata\Util\ClassInfoTrait;
24
use ApiPlatform\Metadata\Util\CloneTrait;
25
use GraphQL\Type\Definition\ResolveInfo;
26

27
/**
28
 * Creates a function resolving a GraphQL subscription of an item.
29
 *
30
 * @author Alan Poulain <contact@alanpoulain.eu>
31
 *
32
 * @deprecated
33
 */
34
final class ItemSubscriptionResolverFactory implements ResolverFactoryInterface
35
{
36
    use ClassInfoTrait;
37
    use CloneTrait;
38

39
    public function __construct(private readonly ReadStageInterface $readStage, private readonly SecurityStageInterface $securityStage, private readonly SerializeStageInterface $serializeStage, private readonly SubscriptionManagerInterface $subscriptionManager, private readonly ?MercureSubscriptionIriGeneratorInterface $mercureSubscriptionIriGenerator)
40
    {
UNCOV
41
    }
8✔
42

43
    public function __invoke(?string $resourceClass = null, ?string $rootClass = null, ?Operation $operation = null, ?PropertyMetadataFactoryInterface $propertyMetadataFactory = null): callable
44
    {
45
        return function (?array $source, array $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass, $operation): ?array {
×
46
            if (null === $resourceClass || null === $operation) {
×
47
                return null;
×
48
            }
49

50
            $resolverContext = ['source' => $source, 'args' => $args, 'info' => $info, 'is_collection' => false, 'is_mutation' => false, 'is_subscription' => true];
×
51

52
            $item = ($this->readStage)($resourceClass, $rootClass, $operation, $resolverContext);
×
53
            if (null !== $item && !\is_object($item)) {
×
54
                throw new \LogicException('Item from read stage should be a nullable object.');
×
55
            }
56
            ($this->securityStage)($resourceClass, $operation, $resolverContext + [
×
57
                'extra_variables' => [
×
58
                    'object' => $item,
×
59
                ],
×
60
            ]);
×
61

62
            $result = ($this->serializeStage)($item, $resourceClass, $operation, $resolverContext);
×
63

64
            $subscriptionId = $this->subscriptionManager->retrieveSubscriptionId($resolverContext, $result);
×
65

66
            if ($subscriptionId && ($mercure = $operation->getMercure())) {
×
67
                if (!$this->mercureSubscriptionIriGenerator) {
×
68
                    throw new \LogicException('Cannot use Mercure for subscriptions when MercureBundle is not installed. Try running "composer require mercure".');
×
69
                }
70

71
                $hub = \is_array($mercure) ? ($mercure['hub'] ?? null) : null;
×
72
                $result['mercureUrl'] = $this->mercureSubscriptionIriGenerator->generateMercureUrl($subscriptionId, $hub);
×
73
            }
74

75
            return $result;
×
76
        };
×
77
    }
78
}
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