Completed
Push — master ( bc7d7f...7a9596 )
by Théo
02:46
created

UpdateConsoleLogger   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 79
c 0
b 0
f 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A noNewRemoteVersions() 0 3 1
A startUpdating() 0 3 1
A updateSuccess() 0 10 1
A printRemoteVersion() 0 6 1
A rollbackFail() 0 3 1
A error() 0 3 1
A currentVersionInstalled() 0 3 1
A updateNotNeeded() 0 6 1
A rollbackSuccess() 0 3 1
A printLocalVersion() 0 5 1
A __construct() 0 3 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\Logger;
16
17
use Symfony\Component\Console\Style\SymfonyStyle;
18
use Throwable;
19
20
/**
21
 * @private
22
 * @final
23
 */
24
class UpdateConsoleLogger
25
{
26
    /**
27
     * @var SymfonyStyle
28
     */
29
    private $io;
30
31
    public function __construct(SymfonyStyle $io)
32
    {
33
        $this->io = $io;
34
    }
35
36
    public function startUpdating(): void
37
    {
38
        $this->io->writeln('Updating...');
39
    }
40
41
    public function updateSuccess(string $newVersion, string $oldVersion): void
42
    {
43
        $this->io->success('PHP-Scoper has been updated.');
44
        $this->io->writeln(sprintf(
45
            'Current version is: <comment>%s</comment>.',
46
            $newVersion
47
        ));
48
        $this->io->writeln(sprintf(
49
            'Previous version was: <comment>%s</comment>.',
50
            $oldVersion
51
        ));
52
    }
53
54
    public function updateNotNeeded(string $oldVersion): void
55
    {
56
        $this->io->writeln('PHP-Scoper is currently up to date.');
57
        $this->io->writeln(sprintf(
58
            'Current version is: <comment>%s</comment>.',
59
            $oldVersion
60
        ));
61
    }
62
63
    public function error(Throwable $e): void
1 ignored issue
show
Unused Code introduced by
The parameter $e is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

63
    public function error(/** @scrutinizer ignore-unused */ Throwable $e): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        $this->io->error('Unexpected error. If updating, your original phar is untouched.');
66
    }
67
68
    public function rollbackSuccess(): void
69
    {
70
        $this->io->success('PHP-Scoper has been rolled back to prior version.');
71
    }
72
73
    public function rollbackFail(): void
74
    {
75
        $this->io->error('Rollback failed for reasons unknown.');
76
    }
77
78
    public function printLocalVersion(string $version): void
79
    {
80
        $this->io->writeln(sprintf(
81
            'Your current local version is: <comment>%s</comment>',
82
            $version
83
        ));
84
    }
85
86
    public function printRemoteVersion(string $stability, string $version): void
87
    {
88
        $this->io->writeln(sprintf(
89
            'The current <comment>%s</comment> build available remotely is: <comment>%s</comment>',
90
            $stability,
91
            $version
92
        ));
93
    }
94
95
    public function noNewRemoteVersions(string $stability): void
96
    {
97
        $this->io->writeln(sprintf('There are no new <comment>%s</comment> builds available.', $stability));
98
    }
99
100
    public function currentVersionInstalled(string $stability): void
101
    {
102
        $this->io->writeln(sprintf('You have the current <comment>%s</comment> build installed.', $stability));
103
    }
104
}
105