Text::message()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
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
 *
8
 * @link    https://github.com/Saibamen/Generate-Sort-Numbers
9
 */
10
11
namespace Includes;
12
13
/**
14
 * Functions for printing text.
15
 */
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()
88
    {
89
        return self::$debugMode;
90
    }
91
}
92