Passed
Pull Request — master (#391)
by Théo
02:24
created

CompileLogger::getIO()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
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\Console\Logger;
16
17
use InvalidArgumentException;
18
use function sprintf;
19
use Symfony\Component\Console\Output\OutputInterface;
20
use Symfony\Component\Console\Style\SymfonyStyle;
21
22
/**
23
 * @internal
24
 */
25
final class CompileLogger
26
{
27
    public const QUESTION_MARK_PREFIX = '?';
28
    public const STAR_PREFIX = '*';
29
    public const PLUS_PREFIX = '+';
30
    public const MINUS_PREFIX = '-';
31
    public const CHEVRON_PREFIX = '>';
32
33
    private $io;
34
35
    public function __construct(SymfonyStyle $io)
36
    {
37
        $this->io = $io;
38
    }
39
40
    public function getIO(): SymfonyStyle
41
    {
42
        return $this->io;
43
    }
44
45
    public function log(string $prefix, string $message, int $verbosity = OutputInterface::OUTPUT_NORMAL): void
46
    {
47
        switch ($prefix) {
48
            case '!':
49
                $prefix = "<error>$prefix</error>";
50
                break;
51
            case self::STAR_PREFIX:
52
                $prefix = "<info>$prefix</info>";
53
                break;
54
            case self::QUESTION_MARK_PREFIX:
55
                $prefix = "<comment>$prefix</comment>";
56
                break;
57
            case self::PLUS_PREFIX:
58
            case self::MINUS_PREFIX:
59
                $prefix = "  <comment>$prefix</comment>";
60
                break;
61
            case self::CHEVRON_PREFIX:
62
                $prefix = "    <comment>$prefix</comment>";
63
                break;
64
            default:
65
                throw new InvalidArgumentException('Expected one of the logger constant as a prefix.');
66
        }
67
68
        $this->io->writeln(
69
            "$prefix $message",
70
            $verbosity
71
        );
72
    }
73
74
    public function logStartBuilding(string $path): void
75
    {
76
        $this->io->writeln(
77
            sprintf(
78
                '🔨  Building the PHAR "<comment>%s</comment>"',
79
                $path
80
            )
81
        );
82
        $this->io->newLine();
83
    }
84
}
85