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

Utils::getDirname()   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 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
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
    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