1 | <?php |
||
2 | |||
3 | /* |
||
4 | * The MIT License |
||
5 | * |
||
6 | * Copyright 2015 James Ekow Abaka Ainooson. |
||
7 | * |
||
8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
||
9 | * of this software and associated documentation files (the "Software"), to deal |
||
10 | * in the Software without restriction, including without limitation the rights |
||
11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||
12 | * copies of the Software, and to permit persons to whom the Software is |
||
13 | * furnished to do so, subject to the following conditions: |
||
14 | * |
||
15 | * The above copyright notice and this permission notice shall be included in |
||
16 | * all copies or substantial portions of the Software. |
||
17 | * |
||
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||
21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||
23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||
24 | * THE SOFTWARE. |
||
25 | */ |
||
26 | |||
27 | namespace yentu; |
||
28 | |||
29 | /** |
||
30 | * Timer class contains routines for timing yentu migrations. |
||
31 | */ |
||
32 | class Timer |
||
33 | { |
||
34 | /** |
||
35 | * The stored start time. |
||
36 | * @var double |
||
37 | */ |
||
38 | private $startTime; |
||
39 | |||
40 | /** |
||
41 | * Singleton instance. |
||
42 | * @var Timer |
||
43 | */ |
||
44 | private static $instance; |
||
45 | |||
46 | /** |
||
47 | * Set the singleton instance. |
||
48 | * @param Timer $instance |
||
49 | */ |
||
50 | public static function setInstance($instance) |
||
51 | { |
||
52 | self::$instance = $instance; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Gets an instance of the Timer. |
||
57 | * @return \yentu\Timer |
||
58 | */ |
||
59 | private static function instance() |
||
60 | { |
||
61 | if(self::$instance === null) |
||
62 | { |
||
63 | self::$instance = new Timer(); |
||
64 | } |
||
65 | return self::$instance; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Start the timer. |
||
70 | */ |
||
71 | public function startInstance() |
||
72 | { |
||
73 | $this->startTime = microtime(true); |
||
0 ignored issues
–
show
|
|||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Stop the timer and return the time elapsed since it was started. |
||
78 | * @return double |
||
79 | */ |
||
80 | public function stopInstance() |
||
81 | { |
||
82 | return microtime(true) - $this->startTime; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Print the time elasped in a pretty format. |
||
87 | * |
||
88 | * @param double $time |
||
89 | * @return string |
||
90 | */ |
||
91 | public static function pretty($time) |
||
92 | { |
||
93 | $millis = ($time - floor($time)) * 1000; |
||
94 | $secs = round($time, 2); |
||
95 | return $secs > 0 ? "{$secs} seconds" : "{$millis} milliseconds"; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * Start the embedded timer instance. |
||
100 | */ |
||
101 | public static function start() |
||
102 | { |
||
103 | self::instance()->startInstance(); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Stop the embeded timer instance and return the time elasped. |
||
108 | * @return double |
||
109 | */ |
||
110 | public static function stop() |
||
111 | { |
||
112 | return self::instance()->stopInstance(); |
||
113 | } |
||
114 | } |
||
115 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.