Passed
Pull Request — master (#56)
by Théo
02:16
created

remove_dir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
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
20
/**
21
 * TODO: this function should be pushed down to the PHAR extension.
22
 */
23
function get_phar_compression_algorithms(): array
24
{
25
    static $algorithms = [
26
        'GZ' => Phar::GZ,
27
        'BZ2' => Phar::BZ2,
28
        'NONE' => Phar::NONE,
29
    ];
30
31
    return $algorithms;
32
}
33
34
function formatted_filesize(string $path)
35
{
36
    Assertion::file($path);
37
38
    $size = filesize($path);
39
    $units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
40
    $power = $size > 0 ? floor(log($size, 1024)) : 0;
41
42
    return sprintf(
43
        '%s%s',
44
        number_format(
45
            $size / (1024 ** $power),
46
            2,
47
            '.',
48
            ','
49
        ),
50
        $units[$power]
51
    );
52
}
53
54
function register_aliases(): void
55
{
56
    if (false === class_exists(\Herrera\Box\Compactor\Javascript::class, false)) {
57
        class_alias(\KevinGH\Box\Compactor\Javascript::class, \Herrera\Box\Compactor\Javascript::class);
58
    }
59
60
    if (false === class_exists(\Herrera\Box\Compactor\Json::class, false)) {
61
        class_alias(\KevinGH\Box\Compactor\Json::class, \Herrera\Box\Compactor\Json::class);
62
    }
63
64
    if (false === class_exists(\Herrera\Box\Compactor\Php::class, false)) {
65
        class_alias(\KevinGH\Box\Compactor\Php::class, \Herrera\Box\Compactor\Php::class);
66
    }
67
}
68