Test Failed
Push — master ( c29f58...4bba41 )
by Julien
10:16 queued 06:00
created

Utils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 12
c 6
b 0
f 0
dl 0
loc 39
ccs 0
cts 11
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUnlimitedRuntime() 0 6 1
A getMemoryUsage() 0 7 1
A getNamespace() 0 3 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
    public static function setUnlimitedRuntime(): void
20
    {
21
        ini_set('memory_limit', -1);
22
        ini_set('max_execution_time', 0);
23
        ini_set('max_input_time', 0);
24
        set_time_limit(0);
25
    }
26
    
27
    /**
28
     * Get the Namespace from a class object
29
     */
30
    public static function getNamespace(object $class): string
31
    {
32
        return (new \ReflectionClass($class))->getNamespaceName();
33
    }
34
    
35
    /**
36
     * Get the directory from a class object
37
     */
38
    public static function getDirname(object $class): string
39
    {
40
        return dirname((new \ReflectionClass($class))->getFileName());
41
    }
42
    
43
    /**
44
     * Return an array of the current memory usage in MB
45
     */
46
    public static function getMemoryUsage(float $divider = 1048576.2, string $suffix = ' MB'): array
47
    {
48
        return [
49
            'memory' => (memory_get_usage() / $divider) . $suffix,
50
            'memoryPeak' => (memory_get_peak_usage() / $divider) . $suffix,
51
            'realMemory' => (memory_get_usage(true) / $divider) . $suffix,
52
            'realMemoryPeak' => (memory_get_peak_usage(true) / $divider) . $suffix,
53
        ];
54
    }
55
}
56