Test Failed
Push — master ( 8960d3...0d17c6 )
by Mehmet
07:55
created

Result   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 77
rs 10
wmc 15

13 Methods

Rating   Name   Duplication   Size   Complexity  
A getRelationshipsDeleted() 0 3 1
A getRelationshipsCreated() 0 3 1
A getPropertiesSet() 0 3 1
A getNodesCreated() 0 3 1
A getLabelsAdded() 0 3 1
A createFromResponse() 0 6 2
A getNodesDeleted() 0 3 1
A __construct() 0 5 1
A prettyPrint() 0 7 2
A getResultSet() 0 3 1
A getExecutionTime() 0 3 1
A getCachedExecution() 0 3 1
A getLabels() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Redislabs\Module\RedisGraph;
6
7
use SevenEcks\Tableify\Tableify;
8
9
class Result
10
{
11
    private ?array $resultSet;
12
    private array $statistics;
13
    private ?array $labels;
14
15
    public function __construct(?array $labels, ?array $resultSet, Statistics $statistics)
16
    {
17
        $this->labels = $labels;
18
        $this->resultSet = $resultSet;
19
        $this->statistics = $statistics->getResultStatistics();
20
    }
21
22
    public static function createFromResponse(array $response): self
23
    {
24
        $stats = $response[2] ?? $response[0];
25
        $resultKeys = isset($response[1]) ? $response[0] : [];
26
        $resultSet = $response[1] ?? [];
27
        return new self($resultKeys, $resultSet, new Statistics($stats));
28
    }
29
30
    public function getResultSet(): array
31
    {
32
        return $this->resultSet;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->resultSet could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
33
    }
34
    public function getLabels(): array
35
    {
36
        return $this->labels;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->labels could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
37
    }
38
39
40
    public function getLabelsAdded(): int
41
    {
42
        return $this->statistics['LABELS_ADDED'];
43
    }
44
45
    public function getNodesCreated(): int
46
    {
47
        return $this->statistics['NODES_CREATED'];
48
    }
49
50
    public function getNodesDeleted(): int
51
    {
52
        return $this->statistics['NODES_DELETED'];
53
    }
54
55
    public function getRelationshipsCreated(): int
56
    {
57
        return $this->statistics['RELATIONSHIPS_CREATED'];
58
    }
59
60
    public function getRelationshipsDeleted(): int
61
    {
62
        return $this->statistics['RELATIONSHIPS_DELETED'];
63
    }
64
65
    public function getExecutionTime(): float
66
    {
67
        return $this->statistics['INTERNAL_EXECUTION_TIME'];
68
    }
69
70
    public function getPropertiesSet(): int
71
    {
72
        return $this->statistics['PROPERTIES_SET'];
73
    }
74
    public function getCachedExecution(): int
75
    {
76
        return $this->statistics['CACHED_EXECUTION'];
77
    }
78
79
    public function prettyPrint(): void
80
    {
81
        $table = Tableify::new(array_merge([$this->labels], $this->resultSet));
0 ignored issues
show
Bug introduced by
It seems like $this->resultSet can also be of type null; however, parameter $arrays of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

81
        $table = Tableify::new(array_merge([$this->labels], /** @scrutinizer ignore-type */ $this->resultSet));
Loading history...
82
        $table = $table->make();
83
        $tableData = $table->toArray();
84
        foreach ($tableData as $row) {
85
            echo $row . "\n";
86
        }
87
    }
88
}
89