Passed
Push — master ( 470cec...646bff )
by Adam
01:33
created

printTimeDuration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Functions for printing text.
4
 *
5
 * @author  Adam "Saibamen" Stachowicz <[email protected]>
6
 */
7
8
namespace Includes\Text;
9
10
/**
11
 * Prints how much time took some action in milliseconds.
12
 *
13
 * @param float|string $startTime Time when action started
14
 */
15
function printTimeDuration($startTime)
16
{
17
    if (gettype($startTime) === 'string') {
18
        $currentTime = microtime();
19
    } else {
20
        $currentTime = microtime(true);
21
    }
22
23
    $completedIn = (float) $currentTime - (float) $startTime;
24
    $completedIn = number_format((float) $completedIn, 4, '.', '');
25
26
    message('It was done in '.$completedIn.' ms.');
27
}
28
29
/**
30
 * Execute message() function if DEBUG is set to true.
31
 *
32
 * @global bool $DEBUG
33
 *
34
 * @param mixed $message Message to print if in DEBUG mode
35
 *
36
 * @see \Includes\Text\message()
37
 */
38
function debug($message)
39
{
40
    if (DEBUG) {
0 ignored issues
show
Bug introduced by
The constant Includes\Text\DEBUG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
        message($message);
42
    }
43
}
44
45
/**
46
 * Prints message with new lines.
47
 *
48
 * @param mixed $message Message to print
49
 */
50
function message($message)
51
{
52
    echo "\n".$message."\n";
53
}
54