Completed
Push — master ( 18b606...1191a0 )
by yuuki
04:00
created

StatementStats::__construct()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 8
nc 8
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Ytake\PrestoClient;
5
6
/**
7
 * Class StatementStats
8
 */
9
final class StatementStats
10
{
11
    /** @var string */
12
    private $state = '';
13
14
    /** @var bool */
15
    private $queued;
16
17
    /** @var bool */
18
    private $scheduled;
19
20
    /** @var int */
21
    private $nodes;
22
23
    /** @var int */
24
    private $totalSplits;
25
26
    /** @var int */
27
    private $queuedSplits;
28
29
    /** @var int */
30
    private $runningSplits;
31
32
    /** @var int */
33
    private $completedSplits;
34
35
    /** @var int */
36
    private $userTimeMillis;
37
38
    /** @var int */
39
    private $cpuTimeMillis;
40
41
    /** @var int */
42
    private $wallTimeMillis;
43
44
    /** @var int */
45
    private $processedRows;
46
47
    /** @var int */
48
    private $processedBytes;
49
50
    /** @var \stdClass */
51
    private $rootStage;
52
53
    /** @var string[] */
54
    private $primitiveCasts = [
55
        'state'           => 'strval',
56
        'queued'          => 'boolval',
57
        'scheduled'       => 'boolval',
58
        'nodes'           => 'intval',
59
        'totalSplits'     => 'intval',
60
        'queuedSplits'    => 'intval',
61
        'runningSplits'   => 'intval',
62
        'completedSplits' => 'intval',
63
        'userTimeMillis'  => 'intval',
64
        'cpuTimeMillis'   => 'intval',
65
        'wallTimeMillis'  => 'intval',
66
        'processedRows'   => 'intval',
67
        'processedBytes'  => 'intval',
68
    ];
69
70
    /**
71
     * StatementStats constructor.
72
     *
73
     * @param \stdClass $jsonContent
74
     */
75
    public function __construct(\stdClass $jsonContent)
76
    {
77
        foreach ($jsonContent as $element => $value) {
0 ignored issues
show
Bug introduced by
The expression $jsonContent of type object<stdClass> is not traversable.
Loading history...
78
            if (property_exists($this, $element)) {
79
                if (isset($this->primitiveCasts[$element])) {
80
                    $castFunction = $this->primitiveCasts[$element];
81
                    $this->$element = $castFunction($value);
82
                }
83
            }
84
        }
85
        if (isset($jsonContent->rootStage)) {
86
            $this->rootStage = $jsonContent->rootStage;
87
        }
88
    }
89
90
    /**
91
     * @return string
92
     */
93
    public function getState(): string
94
    {
95
        return $this->state;
96
    }
97
98
    /**
99
     * @return bool
100
     */
101
    public function isQueued(): bool
102
    {
103
        return $this->queued;
104
    }
105
106
    /**
107
     * @return bool
108
     */
109
    public function isScheduled(): bool
110
    {
111
        return $this->scheduled;
112
    }
113
114
    /**
115
     * @return int
116
     */
117
    public function getNodes(): int
118
    {
119
        return $this->nodes;
120
    }
121
122
    /**
123
     * @return int
124
     */
125
    public function getTotalSplits(): int
126
    {
127
        return $this->totalSplits;
128
    }
129
130
    /**
131
     * @return int
132
     */
133
    public function getQueuedSplits(): int
134
    {
135
        return $this->queuedSplits;
136
    }
137
138
    /**
139
     * @return int
140
     */
141
    public function getRunningSplits(): int
142
    {
143
        return $this->runningSplits;
144
    }
145
146
    /**
147
     * @return int
148
     */
149
    public function getCompletedSplits(): int
150
    {
151
        return $this->completedSplits;
152
    }
153
154
    /**
155
     * @return int
156
     */
157
    public function getUserTimeMillis(): int
158
    {
159
        return $this->userTimeMillis;
160
    }
161
162
    /**
163
     * @return int
164
     */
165
    public function getCpuTimeMillis(): int
166
    {
167
        return $this->cpuTimeMillis;
168
    }
169
170
    /**
171
     * @return int
172
     */
173
    public function getWallTimeMillis(): int
174
    {
175
        return $this->wallTimeMillis;
176
    }
177
178
    /**
179
     * @return int
180
     */
181
    public function getProcessedRows(): int
182
    {
183
        return $this->processedRows;
184
    }
185
186
    /**
187
     * @return int
188
     */
189
    public function getProcessedBytes(): int
190
    {
191
        return $this->processedBytes;
192
    }
193
194
    /**
195
     * @return \stdClass|null
196
     */
197
    public function getRootStage()
198
    {
199
        return $this->rootStage;
200
    }
201
}
202