Issues (224)

src/Phar/CompressionAlgorithm.php (4 issues)

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\Phar;
16
17
use Phar;
18
use function array_keys;
19
use function array_search;
20
21
/**
22
 * The required extension to execute the PHAR now that it is compressed.
23
 *
24
 * This is a tiny wrapper around the PHAR compression algorithm
25
 * to make it a bit more type-safe and convenient to work with.
26
 *
27
 * @private
28
 */
29
enum CompressionAlgorithm: int
30
{
31
    case GZ = Phar::GZ;
32
    case BZ2 = Phar::BZ2;
33
    case NONE = Phar::NONE;
34
35
    private const LABELS = [
36
        'GZ' => self::GZ,
37
        'BZ2' => self::BZ2,
38
        'NONE' => self::NONE,
39
    ];
40
41
    /**
42
     * @return list<string>
0 ignored issues
show
The type KevinGH\Box\Phar\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
     */
44
    public static function getLabels(): array
45
    {
46
        return array_keys(self::LABELS);
0 ignored issues
show
The constant KevinGH\Box\Phar\CompressionAlgorithm::LABELS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug Best Practice introduced by
The expression return array_keys(self::LABELS) returns the type array which is incompatible with the documented return type KevinGH\Box\Phar\list.
Loading history...
47
    }
48
49
    public static function fromLabel(?string $label): self
50
    {
51
        return match ($label) {
52
            'BZ2' => self::BZ2,
53
            'GZ' => self::GZ,
54
            'NONE', null => self::NONE,
55
        };
56
    }
57
58
    public function getLabel(): string
59
    {
60
        return array_search($this, self::LABELS, true);
0 ignored issues
show
The constant KevinGH\Box\Phar\CompressionAlgorithm::LABELS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
61
    }
62
63
    public function getRequiredExtension(): ?string
64
    {
65
        return match ($this) {
66
            self::BZ2 => 'bz2',
67
            self::GZ => 'zlib',
68
            self::NONE => null,
69
        };
70
    }
71
}
72