Test Failed
Push — master ( baa3df...d825b9 )
by Julien
04:52
created

Utils::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit;
13
14
class Utils
15
{
16
    /**
17
     * Remove time and memory limits
18
     */
19 1
    public static function setUnlimitedRuntime(): void
20
    {
21 1
        ini_set('memory_limit', -1);
22 1
        ini_set('max_execution_time', 0);
23 1
        ini_set('max_input_time', 0);
24 1
        set_time_limit(0);
25
    }
26
    
27
    /**
28
     * Get the Namespace from a class object
29
     */
30 1
    public static function getNamespace(object $class): string
31
    {
32 1
        return (new \ReflectionClass($class))->getNamespaceName();
33
    }
34
    
35
    /**
36
     * Get the Namespace from a class object
37
     */
38
    public static function getShortName(object $class): string
39
    {
40
        return (new \ReflectionClass($class))->getShortName();
41
    }
42
    
43
    /**
44
     * Get the Namespace from a class object
45
     */
46
    public static function getName(object $class): string
47
    {
48
        return (new \ReflectionClass($class))->getName();
49
    }
50
    
51
    /**
52
     * Get the directory from a class object
53
     */
54 1
    public static function getDirname(object $class): string
55
    {
56 1
        return dirname((new \ReflectionClass($class))->getFileName());
57
    }
58
    
59
    /**
60
     * Return an array of the current memory usage in MB
61
     */
62 1
    public static function getMemoryUsage(float $divider = 1048576.2, string $suffix = ' MB'): array
63
    {
64 1
        return [
65 1
            'memory' => (memory_get_usage() / $divider) . $suffix,
66 1
            'memoryPeak' => (memory_get_peak_usage() / $divider) . $suffix,
67 1
            'realMemory' => (memory_get_usage(true) / $divider) . $suffix,
68 1
            'realMemoryPeak' => (memory_get_peak_usage(true) / $divider) . $suffix,
69 1
        ];
70
    }
71
}
72