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

Utils   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 14
c 7
b 0
f 0
dl 0
loc 55
ccs 15
cts 19
cp 0.7895
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUnlimitedRuntime() 0 6 1
A getNamespace() 0 3 1
A getShortName() 0 3 1
A getName() 0 3 1
A getMemoryUsage() 0 7 1
A getDirname() 0 3 1
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