Passed
Push — master ( d735d3...29fa29 )
by Yannick
18:02 queued 07:53
created

LoggingExecutor::executeQuery()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 19
c 1
b 0
f 0
nc 2
nop 8
dl 0
loc 36
rs 9.6333

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\GraphQL;
8
9
use ApiPlatform\GraphQl\ExecutorInterface;
10
use GraphQL\GraphQL;
11
use GraphQL\Type\Schema;
12
use GraphQL\Executor\ExecutionResult;
13
use Psr\Log\LoggerInterface;
14
15
class LoggingExecutor implements ExecutorInterface
16
{
17
    private LoggerInterface $logger;
18
19
    public function __construct(LoggerInterface $logger)
20
    {
21
        $this->logger = $logger;
22
    }
23
24
    public function executeQuery(
25
        Schema $schema,
26
               $source,
27
               $rootValue = null,
28
               $context = null,
29
        array $variableValues = null,
30
        string $operationName = null,
31
        callable $fieldResolver = null,
32
        array $validationRules = null
33
    ): ExecutionResult {
34
        $result = GraphQL::executeQuery(
35
            $schema,
36
            $source,
37
            $rootValue,
38
            $context,
39
            $variableValues,
40
            $operationName,
41
            $fieldResolver,
42
            $validationRules
43
        );
44
45
        if (!empty($result->errors)) {
46
            foreach ($result->errors as $error) {
47
                $msg = '[GraphQL Error] '.$error->getMessage();
48
                error_log($msg);
49
50
                $this->logger->error($msg, [
51
                    'debugMessage' => $error->getPrevious()?->getMessage() ?? null,
52
                    'path' => $error->getPath(),
53
                    'locations' => $error->getLocations(),
54
                    'extensions' => $error->getExtensions(),
55
                ]);
56
            }
57
        }
58
59
        return $result;
60
    }
61
}
62