Test Failed
Push — main ( 397c3b...9ee4d3 )
by Rafael
43:59
created

defineIfNotDefined()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Disable unused stream wrappers
5
 *
6
 * @param array|null $streamsToDisable
7
 *
8
 * @return bool
9
 */
10
function unregisterStreamWrappers(array $streamsToDisable = null)
11
{
12
    if (!isset($streamsToDisable)) {
13
        $streamsToDisable = ['compress.zlib', 'compress.bzip2', 'ftp', 'ftps', 'glob', 'data', 'expect', 'ogg', 'rar', 'zip', 'zlib'];
14
    }
15
16
    $ok = true;
17
    $wrappers = stream_get_wrappers();
18
    foreach ($streamsToDisable as $streamToDisable) {
19
        if (!in_array($streamToDisable, $wrappers)) {
20
            continue;
21
        }
22
23
        $ok = $ok && stream_wrapper_unregister($streamToDisable);
24
    }
25
26
    return $ok;
27
}
28
29
/**
30
 * Defines the constant $name, if it is not already defined.
31
 *
32
 * @param string $name
33
 * @param        $value
34
 */
35
function defineIfNotDefined(string $name, $value)
36
{
37
    if (!defined($name)) {
38
        define($name, $value);
39
    }
40
}
41