Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
BO\Zmsdldb\Importer\print_rFnArgs | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
Timer | |
0.00% |
0 / 23 |
|
0.00% |
0 / 11 |
210 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
start | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
stop | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
pause | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
resume | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTime | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getLapTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMicroTime | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
timeToString | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
roundMicroTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
__destruct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdldb\Importer; |
4 | |
5 | define('DEBUG', true); |
6 | |
7 | class Timer |
8 | { |
9 | protected $start; |
10 | protected $pause; |
11 | protected $stop; |
12 | protected $elapsed;# = 0; |
13 | |
14 | public function __construct() |
15 | { |
16 | $this->start(); |
17 | if (true === DEBUG) { |
18 | echo 'Working - please wait...' . PHP_EOL; |
19 | } |
20 | } |
21 | |
22 | public function start() |
23 | { |
24 | $this->start = Timer::getMicroTime(); |
25 | } |
26 | |
27 | public function stop() |
28 | { |
29 | $this->stop = Timer::getMicroTime(); |
30 | } |
31 | |
32 | public function pause() |
33 | { |
34 | $this->pause = Timer::getMicroTime(); |
35 | $this->elapsed += ($this->pause - $this->start); |
36 | } |
37 | |
38 | public function resume() |
39 | { |
40 | $this->start = Timer::getMicroTime(); |
41 | } |
42 | |
43 | public function getTime() |
44 | { |
45 | if (!isset($this->stop)) { |
46 | $this->stop = Timer::getMicroTime(); |
47 | } |
48 | return $this->timeToString(); |
49 | } |
50 | |
51 | protected function getLapTime() |
52 | { |
53 | return $this->timeToString(); |
54 | } |
55 | |
56 | protected static function getMicroTime() |
57 | { |
58 | list($usec, $sec) = explode(' ', microtime()); |
59 | return ((float) $usec + (float) $sec); |
60 | } |
61 | |
62 | protected function timeToString() |
63 | { |
64 | $seconds = ($this->stop - $this->start) + $this->elapsed; |
65 | $seconds = Timer::roundMicroTime($seconds); |
66 | $hours = floor($seconds / (60 * 60)); |
67 | $divisorForMinutes = $seconds % (60 * 60); |
68 | $minutes = floor($divisorForMinutes / 60); |
69 | return $hours . "h:" . $minutes . "m:" . $seconds . "s"; |
70 | } |
71 | |
72 | protected static function roundMicroTime($microTime) |
73 | { |
74 | return round($microTime, 4, PHP_ROUND_HALF_UP); |
75 | } |
76 | |
77 | public function __destruct() |
78 | { |
79 | if (true === DEBUG) { |
80 | echo 'Job finished in ' . $this->getTime() . PHP_EOL; |
81 | } |
82 | } |
83 | } |
84 | |
85 | function print_rFnArgs() |
86 | { |
87 | print_r(func_get_args()); |
88 | } |