Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 6f78dc...d7c2e2 )
by Jérémiah
21s queued 11s
created

ProfilerController::__invoke()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 37
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 6.0026

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 37
ccs 23
cts 24
cp 0.9583
rs 8.9137
c 2
b 0
f 0
cc 6
nc 4
nop 2
crap 6.0026
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\Profiler\Profiler;
13
use Symfony\Component\Routing\RouterInterface;
14
use Twig\Environment;
15
use Twig\Error\LoaderError;
16
use Twig\Error\RuntimeError;
17
use Twig\Error\SyntaxError;
18
use function array_map;
19
20
class ProfilerController
21
{
22
    private ?Profiler $profiler;
23
    private ?Environment $twig;
24
    private string $endpointUrl;
25
    private RequestExecutor $requestExecutor;
26
    private ?string $queryMatch;
27
28 3
    public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch)
29
    {
30 3
        $this->profiler = $profiler;
31 3
        $this->twig = $twig;
32 3
        $this->endpointUrl = $router->generate('overblog_graphql_endpoint');
33 3
        $this->requestExecutor = $requestExecutor;
34 3
        $this->queryMatch = $queryMatch;
35 3
    }
36
37
    /**
38
     * @throws LoaderError
39
     * @throws RuntimeError
40
     * @throws SyntaxError
41
     */
42 3
    public function __invoke(Request $request, string $token): Response
43
    {
44 3
        if (null === $this->profiler) {
45 1
            throw new ServiceNotFoundException('The profiler must be enabled.');
46
        }
47
48 2
        if (null === $this->twig) {
49 1
            throw new ServiceNotFoundException('The GraphQL Profiler require twig');
50
        }
51
52 1
        $this->profiler->disable();
53
54 1
        $profile = $this->profiler->loadProfile($token);
55
56 1
        $tokens = array_map(function ($tokenData) {
57 1
            $profile = $this->profiler->loadProfile($tokenData['token']);
0 ignored issues
show
Bug introduced by
The method loadProfile() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            /** @scrutinizer ignore-call */ 
58
            $profile = $this->profiler->loadProfile($tokenData['token']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
58 1
            if (!$profile->hasCollector('graphql')) {
59
                return false;
60
            }
61 1
            $tokenData['graphql'] = $profile->getCollector('graphql');
62
63 1
            return $tokenData;
64 1
        }, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, '100', 'POST', null, null, null)); // @phpstan-ignore-line
65
66 1
        $schemas = [];
67 1
        foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
68 1
            $schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName));
69
        }
70
71 1
        return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [
72 1
            'request' => $request,
73 1
            'profile' => $profile,
74 1
            'tokens' => array_filter($tokens),
75 1
            'token' => $token,
76
            'panel' => null,
77 1
            'schemas' => $schemas,
78 1
        ]), 200, ['Content-Type' => 'text/html']);
79
    }
80
}
81