mkorkmaz /
redislabs-redisgraph-php
| 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
Loading history...
|
|||||
| 29 | } |
||||
| 30 | public function getLabels(): array |
||||
| 31 | { |
||||
| 32 | return $this->labels; |
||||
|
0 ignored issues
–
show
|
|||||
| 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
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
Loading history...
|
|||||
| 78 | $table = $table->make(); |
||||
| 79 | $tableData = $table->toArray(); |
||||
| 80 | foreach ($tableData as $row) { |
||||
| 81 | echo $row . "\n"; |
||||
| 82 | } |
||||
| 83 | } |
||||
| 84 | } |
||||
| 85 |