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

overblog / GraphQLBundle / 6390260363

03 Oct 2023 08:01AM UTC coverage: 98.83% (-0.02%) from 98.852%
6390260363

push

github

web-flow
Merge pull request #1133 from aviator-ua/fix-deprecation-warning-014

Fix deprecation warning for PHP 8.2

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

4309 of 4360 relevant lines covered (98.83%)

39.02 hits per line

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

93.75
/src/Controller/ProfilerController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Overblog\GraphQLBundle\Controller;
6

7
use GraphQL\Utils\SchemaPrinter;
8
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
9
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\HttpKernel\Kernel;
13
use Symfony\Component\HttpKernel\Profiler\Profiler;
14
use Symfony\Component\Routing\RouterInterface;
15
use Twig\Environment;
16
use Twig\Error\LoaderError;
17
use Twig\Error\RuntimeError;
18
use Twig\Error\SyntaxError;
19
use function array_map;
20

21
class ProfilerController
22
{
23
    private ?Profiler $profiler;
24
    private ?Environment $twig;
25
    private string $endpointUrl;
26
    private RequestExecutor $requestExecutor;
27
    private ?string $queryMatch;
28

29
    public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch)
30
    {
31
        $this->profiler = $profiler;
3✔
32
        $this->twig = $twig;
3✔
33
        $this->endpointUrl = $router->generate('overblog_graphql_endpoint');
3✔
34
        $this->requestExecutor = $requestExecutor;
3✔
35
        $this->queryMatch = $queryMatch;
3✔
36
    }
3✔
37

38
    /**
39
     * @throws LoaderError
40
     * @throws RuntimeError
41
     * @throws SyntaxError
42
     */
43
    public function __invoke(Request $request, string $token): Response
44
    {
45
        if (null === $this->profiler) {
3✔
46
            throw new ServiceNotFoundException('The profiler must be enabled.');
1✔
47
        }
48

49
        if (null === $this->twig) {
2✔
50
            throw new ServiceNotFoundException('The GraphQL Profiler require twig');
1✔
51
        }
52

53
        $this->profiler->disable();
1✔
54

55
        $profile = $this->profiler->loadProfile($token);
1✔
56
        // Type hint as int for the $limit argument of the find method was updated in Symfony 5.4.22 and 6.2.8
57
        // @phpstan-ignore-next-line
58
        $limit = (Kernel::VERSION_ID >= 60208 || (Kernel::MAJOR_VERSION === 5 && Kernel::VERSION_ID >= 50422))
1✔
59
            ? 100
×
60
            : '100';
1✔
61

62
        $tokens = array_map(function ($tokenData) {
1✔
63
            $profile = $this->profiler->loadProfile($tokenData['token']);
1✔
64
            if (!$profile->hasCollector('graphql')) {
1✔
65
                return false;
×
66
            }
67
            $tokenData['graphql'] = $profile->getCollector('graphql');
1✔
68

69
            return $tokenData;
1✔
70
        }, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line
1✔
71

72
        $schemas = [];
1✔
73
        foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
1✔
74
            $schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName));
1✔
75
        }
76

77
        return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [
1✔
78
            'request' => $request,
1✔
79
            'profile' => $profile,
1✔
80
            'tokens' => array_filter($tokens),
1✔
81
            'token' => $token,
1✔
82
            'panel' => null,
83
            'schemas' => $schemas,
1✔
84
        ]), 200, ['Content-Type' => 'text/html']);
1✔
85
    }
86
}
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