Failed Conditions
Push — master ( 34a070...6c283c )
by Adrien
05:56
created

Utility::printFiles()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
ccs 0
cts 7
cp 0
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application;
6
7
use Cake\Chronos\Chronos;
8
9
abstract class Utility
10
{
11
    /**
12
     * @var Chronos
13
     */
14
    private static $now;
15
16
    /**
17
     * Returns now, always same value for a single PHP execution
18
     *
19
     * @return Chronos
20
     */
21 8
    public static function getNow(): Chronos
22
    {
23 8
        if (!self::$now) {
24 1
            self::$now = new Chronos();
25
        }
26
27 8
        return self::$now;
28
    }
29
30
    /**
31
     * Returns the short class name of any object, eg: Application\Model\Calendar => Calendar
32
     *
33
     * @param object $object
34
     *
35
     * @return string
36
     */
37 8
    public static function getShortClassName($object): string
38
    {
39 8
        $reflect = new \ReflectionClass($object);
40
41 8
        return $reflect->getShortName();
42
    }
43
44
    /**
45
     * Print a list of files if non empty
46
     *
47
     * @param string $title
48
     * @param array $files
49
     */
50
    public static function printFiles(string $title, array $files): void
51
    {
52
        if (!$files) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
53
            return;
54
        }
55
56
        echo $title . PHP_EOL . PHP_EOL;
57
58
        foreach ($files as $file) {
59
            echo '    ' . escapeshellarg($file) . PHP_EOL;
60
        }
61
        echo PHP_EOL;
62
    }
63
}
64