Passed
Push — master ( 6da5d7...adffdc )
by Adam
01:50
created

Text::printTimeDuration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Includes/Text.php
4
 *
5
 * @author  Adam "Saibamen" Stachowicz <[email protected]>
6
 * @license MIT
7
 * @link    https://github.com/Saibamen/Generate-Sort-Numbers
8
 */
9
10
namespace Includes;
11
12
/**
13
 * Functions for printing text.
14
 */
15
class Text
16
{
17
    /**
18
     * @var bool If true - print more information.
19
     */
20
    private static $debugMode = false;
0 ignored issues
show
Unused Code introduced by
The property $debugMode is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

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