Total Complexity | 7 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
16 | class Text |
||
17 | { |
||
18 | /** |
||
19 | * @var bool If true - print more information. |
||
20 | */ |
||
21 | private static $debugMode = false; |
||
22 | |||
23 | /** |
||
24 | * Prints how much time took some action in seconds. |
||
25 | * |
||
26 | * @param float|string $startTime Time when action started |
||
27 | */ |
||
28 | public static function printTimeDuration($startTime) |
||
29 | { |
||
30 | $currentTime = microtime(true); |
||
31 | |||
32 | if (gettype($startTime) === 'string') { |
||
33 | $currentTime = microtime(); |
||
34 | } |
||
35 | |||
36 | $completedIn = (float) $currentTime - (float) $startTime; |
||
37 | $completedIn = number_format((float) $completedIn, 4, '.', ''); |
||
38 | |||
39 | self::message('It was done in '.$completedIn.' sec.'); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Execute message() function if $debugMode is set to true. |
||
44 | * |
||
45 | * @param mixed $message Message to print if in DEBUG mode |
||
46 | * |
||
47 | * @see Text::$debugMode |
||
48 | * @see Text::getDebug() |
||
49 | * @see Text::message() |
||
50 | */ |
||
51 | public static function debug($message) |
||
52 | { |
||
53 | if (self::getDebug()) { |
||
54 | self::message($message); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Prints message with new lines. |
||
60 | * |
||
61 | * @param mixed $message Message to print |
||
62 | */ |
||
63 | public static function message($message) |
||
64 | { |
||
65 | echo "\n".$message."\n"; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Set $debugMode property value. |
||
70 | * |
||
71 | * @param bool $value |
||
72 | * |
||
73 | * @see Text::$debugMode |
||
74 | */ |
||
75 | public static function setDebug($value) |
||
76 | { |
||
77 | self::$debugMode = $value; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Get $debugMode property value. |
||
82 | * |
||
83 | * @return bool |
||
84 | * |
||
85 | * @see Text::$debugMode |
||
86 | */ |
||
87 | public static function getDebug() |
||
90 | } |
||
91 | } |
||
92 |