GraphQLManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 51
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A query() 0 11 3
A getSchema() 0 8 2
1
<?php
2
3
namespace Arthem\GraphQLMapper;
4
5
use Arthem\GraphQLMapper\Exception\QueryException;
6
use Arthem\GraphQLMapper\Schema\SchemaFactory;
7
use GraphQL\Executor\ExecutionResult;
8
use GraphQL\GraphQL;
9
use GraphQL\Schema;
10
11
class GraphQLManager
12
{
13
    /**
14
     * @var SchemaFactory
15
     */
16
    private $schemaFactory;
17
18
    /**
19
     * @var Schema
20
     */
21
    protected $schema;
22
23
    /**
24
     * @param SchemaFactory $schemaFactory
25
     */
26
    public function __construct(SchemaFactory $schemaFactory)
27
    {
28
        $this->schemaFactory = $schemaFactory;
29
    }
30
31
    /**
32
     * @param string      $requestString
33
     * @param mixed       $rootValue
34
     * @param array|null  $variableValues
35
     * @param string|null $operationName
36
     * @return ExecutionResult
37
     */
38
    public function query($requestString, $rootValue = null, $variableValues = null, $operationName = null)
39
    {
40
        $schema = $this->getSchema();
41
        $result = GraphQL::execute($schema, $requestString, $rootValue, $variableValues, $operationName);
0 ignored issues
show
Bug introduced by
It seems like $operationName defined by parameter $operationName on line 38 can also be of type string; however, GraphQL\GraphQL::execute() does only seem to accept array|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42
43
        if (is_array($result) && isset($result['errors'])) {
44
            throw new QueryException($result['errors']);
45
        }
46
47
        return $result;
48
    }
49
50
    /**
51
     * @return Schema
52
     */
53
    private function getSchema()
54
    {
55
        if (null === $this->schema) {
56
            $this->schema = $this->schemaFactory->createSchema();
57
        }
58
59
        return $this->schema;
60
    }
61
}
62