Completed
Pull Request — master (#25)
by Théo
04:09 queued 01:37
created

get_phar_compression_algorithms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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 Phar;
18
use ReflectionClass;
19
use Symfony\Component\Filesystem\Filesystem;
20
use Webmozart\PathUtil\Path;
21
22
function canonicalize(string $path): string
23
{
24
    $lastChar = substr($path, -1);
25
26
    $canonical = Path::canonicalize($path);
27
28
    return '/' === $lastChar ? $canonical.$lastChar : $canonical;
29
}
30
31
function is_absolute(string $path): bool
32
{
33
    static $fileSystem;
34
35
    if (null === $fileSystem) {
36
        $fileSystem = new Filesystem();
37
    }
38
39
    return $fileSystem->isAbsolutePath($path);
40
}
41
42
/**
43
 * TODO: this function should be pushed down to the PHAR extension
44
 */
45
function get_phar_compression_algorithms(): array
46
{
47
    static $algorithms = [
48
        'GZ' => Phar::GZ,
49
        'BZ2' => Phar::BZ2,
50
        'NONE' => Phar::NONE,
51
    ];
52
53
    return $algorithms;
54
}
55
56
function register_aliases(): void
57
{
58
    if (false === class_exists(\Herrera\Box\Compactor\Javascript::class, false)) {
59
        class_alias(\KevinGH\Box\Compactor\Javascript::class, \Herrera\Box\Compactor\Javascript::class);
60
    }
61
62
    if (false === class_exists(\Herrera\Box\Compactor\Json::class, false)) {
63
        class_alias(\KevinGH\Box\Compactor\Json::class, \Herrera\Box\Compactor\Json::class);
64
    }
65
66
    if (false === class_exists(\Herrera\Box\Compactor\Php::class, false)) {
67
        class_alias(\KevinGH\Box\Compactor\Php::class, \Herrera\Box\Compactor\Php::class);
68
    }
69
}
70