Passed
Push — master ( e5b7b4...ec2be8 )
by Julien
14:08
created

Utils::dd()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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
use Phalcon\Debug\Dump;
15
16
/**
17
 * Class Utils
18
 */
19
class Utils
20
{
21
    /**
22
     * Remove time and memory limits
23
     */
24
    public static function setUnlimitedRuntime(): void
25
    {
26
        ini_set('memory_limit', -1);
27
        ini_set('max_execution_time', 0);
28
        ini_set('max_input_time', 0);
29
        set_time_limit(0);
30
    }
31
    
32
    /**
33
     * Set max upload file size and post size
34
     * @link https://www.php.net/manual/en/ini.list.php
35
     * @link https://www.php.net/manual/en/configuration.changes.modes.php
36
     * @deprecated This setting must be changed at the system level
37
     * @throws \Exception
38
     */
39
    public static function setMaxUploadFileSize(string $size = '2M'): void
0 ignored issues
show
Unused Code introduced by
The parameter $size is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
    public static function setMaxUploadFileSize(/** @scrutinizer ignore-unused */ string $size = '2M'): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        throw new \Exception('This setting must be changed at the system level.');
42
    }
43
    
44
    /**
45
     * Get the Namespace from a class object
46
     */
47
    public static function getNamespace(object $class): string
48
    {
49
        return (new \ReflectionClass($class))->getNamespaceName();
50
    }
51
    
52
    /**
53
     * Get the directory from a class object
54
     */
55
    public static function getDirname(object $class): string
56
    {
57
        return dirname((new \ReflectionClass($class))->getFileName());
58
    }
59
    
60
    /**
61
     * Return an array of the current memory usage in MB
62
     */
63
    public static function getMemoryUsage(): array
64
    {
65
        $toMB = 1048576.2;
66
        return [
67
            'memory' => (memory_get_usage() / $toMB) . ' MB',
68
            'memoryPeak' => (memory_get_peak_usage() / $toMB) . ' MB',
69
            'realMemory' => (memory_get_usage(true) / $toMB) . ' MB',
70
            'realMemoryPeak' => (memory_get_peak_usage(true) / $toMB) . ' MB',
71
        ];
72
    }
73
}
74
75
if (!function_exists('dd')) {
76
    /**
77
     * Dump the passed variables and end the script.
78
     */
79
    function dd(...$params): void
80
    {
81
        dump(...$params);
82
        exit(1);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
83
    }
84
}
85
86
if (!function_exists('dump')) {
87
    /**
88
     * Dump the passed variables without ending the script.
89
     */
90
    function dump(...$params): void
91
    {
92
        foreach ($params as $param) {
93
            $ret = (new Dump([], true))->variable($param);
94
            if (PHP_SAPI === 'cli') {
95
                $ret = strip_tags($ret) . PHP_EOL;
96
            }
97
            echo $ret;
98
        }
99
    }
100
}
101