Passed
Push — master ( d36bfc...8d22c8 )
by Théo
02:06
created

enable_debug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box;
16
17
use Assert\Assertion;
18
use Phar;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use function constant;
21
use function define;
22
use function defined;
23
24
/**
25
 * @internal
26
 * @private
27
 */
28
const NO_PARALLEL_PROCESSING = 'KevinGH\Box\BOX_NO_PARALLEL_PROCESSING';
29
30
/**
31
 * TODO: this function should be pushed down to the PHAR extension.
32
 *
33
 * @private
34
 */
35
function get_phar_compression_algorithms(): array
36
{
37
    static $algorithms = [
38
        'GZ' => Phar::GZ,
39
        'BZ2' => Phar::BZ2,
40
        'NONE' => Phar::NONE,
41
    ];
42
43
    return $algorithms;
44
}
45
46
/**
47
 * @private
48
 */
49
function formatted_filesize(string $path)
50
{
51
    Assertion::file($path);
52
53
    $size = filesize($path);
54
    $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
55
    $power = $size > 0 ? floor(log($size, 1024)) : 0;
56
57
    return sprintf(
58
        '%s%s',
59
        number_format(
60
            $size / (1024 ** $power),
61
            2,
62
            '.',
63
            ','
64
        ),
65
        $units[$power]
66
    );
67
}
68
69
/**
70
 * @private
71
 */
72
function register_aliases(): void
73
{
74
    // Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file.
75
    if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) {
76
        class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class);
77
    }
78
79
    // Register compactors aliases
80
    if (false === class_exists(\Herrera\Box\Compactor\Javascript::class, false)) {
81
        class_alias(\KevinGH\Box\Compactor\Javascript::class, \Herrera\Box\Compactor\Javascript::class);
82
    }
83
84
    if (false === class_exists(\Herrera\Box\Compactor\Json::class, false)) {
85
        class_alias(\KevinGH\Box\Compactor\Json::class, \Herrera\Box\Compactor\Json::class);
86
    }
87
88
    if (false === class_exists(\Herrera\Box\Compactor\Php::class, false)) {
89
        class_alias(\KevinGH\Box\Compactor\Php::class, \Herrera\Box\Compactor\Php::class);
90
    }
91
}
92
93
/**
94
 * @private
95
 */
96
function disable_parallel_processing(): void
97
{
98
    define(NO_PARALLEL_PROCESSING, true);
99
}
100
101
/**
102
 * @private
103
 */
104
function is_parallel_processing_enabled(): bool
105
{
106
    return false === defined(NO_PARALLEL_PROCESSING) || false === constant(NO_PARALLEL_PROCESSING);
107
}
108