Result::getNodesDeleted()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 $statistics;
12
13
    public function __construct(private ?array $labels, private ?array $resultSet, Statistics $statistics)
14
    {
15
        $this->statistics = $statistics->getResultStatistics();
16
    }
17
18
    public static function createFromResponse(array $response): self
19
    {
20
        $stats = $response[2] ?? $response[0];
21
        $resultKeys = isset($response[1]) ? $response[0] : [];
22
        $resultSet = $response[1] ?? [];
23
        return new self($resultKeys, $resultSet, new Statistics($stats));
24
    }
25
26
    public function getResultSet(): array
27
    {
28
        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...
29
    }
30
    public function getLabels(): array
31
    {
32
        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...
33
    }
34
35
36
    public function getLabelsAdded(): int
37
    {
38
        return $this->statistics['LABELS_ADDED'];
39
    }
40
41
    public function getNodesCreated(): int
42
    {
43
        return $this->statistics['NODES_CREATED'];
44
    }
45
46
    public function getNodesDeleted(): int
47
    {
48
        return $this->statistics['NODES_DELETED'];
49
    }
50
51
    public function getRelationshipsCreated(): int
52
    {
53
        return $this->statistics['RELATIONSHIPS_CREATED'];
54
    }
55
56
    public function getRelationshipsDeleted(): int
57
    {
58
        return $this->statistics['RELATIONSHIPS_DELETED'];
59
    }
60
61
    public function getExecutionTime(): float
62
    {
63
        return $this->statistics['INTERNAL_EXECUTION_TIME'];
64
    }
65
66
    public function getPropertiesSet(): int
67
    {
68
        return $this->statistics['PROPERTIES_SET'];
69
    }
70
    public function getCachedExecution(): int
71
    {
72
        return $this->statistics['CACHED_EXECUTION'];
73
    }
74
75
    public function prettyPrint(): void
76
    {
77
        $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

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