Completed
Push — 1.7 ( 74350c )
by Luis
10:51
created

UpdaterDisplay   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A newVersion() 0 5 1
A error() 0 3 1
A rollbackMessage() 0 6 2
A currentLocalVersion() 0 5 1
A __construct() 0 3 1
A alreadyUpToDate() 0 3 1
A noUpdateApplied() 0 6 1
A updateApplied() 0 10 1
A noUpdatesAvailable() 0 3 1
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Console;
9
10
use Exception;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Output\StreamOutput;
13
14
class UpdaterDisplay
15
{
16
    /** @var OutputInterface */
17
    private $output;
18
19
    public function __construct(OutputInterface $output = null)
20
    {
21
        $this->output = $output ?? new StreamOutput(fopen('php://memory', 'w', false));
0 ignored issues
show
Bug introduced by
It seems like fopen('php://memory', 'w', false) can also be of type false; however, parameter $stream of Symfony\Component\Consol...amOutput::__construct() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

21
        $this->output = $output ?? new StreamOutput(/** @scrutinizer ignore-type */ fopen('php://memory', 'w', false));
Loading history...
22
    }
23
24
    public function rollbackMessage(bool $result): void
25
    {
26
        if ($result) {
27
            $this->output->writeln('<info>phUML has been rolled back to prior version.</info>');
28
        } else {
29
            $this->output->writeln('<error>Rollback failed for unknown reasons.</error>');
30
        }
31
    }
32
33
    public function currentLocalVersion(string $version): void
34
    {
35
        $this->output->writeln(sprintf(
36
            'Your current local build version is: <options=bold>%s</options=bold>',
37
            $version
38
        ));
39
    }
40
41
    public function newVersion(string $newVersion): void
42
    {
43
        $this->output->writeln(sprintf(
44
            'The current stable build available remotely is: <options=bold>%s</options=bold>',
45
            $newVersion
46
        ));
47
    }
48
49
    public function noUpdatesAvailable(): void
50
    {
51
        $this->output->writeln('There are no stable builds available.');
52
    }
53
54
    public function alreadyUpToDate(): void
55
    {
56
        $this->output->writeln('You have the current stable build installed.');
57
    }
58
59
    public function updateApplied(string $oldVersion, string $newVersion): void
60
    {
61
        $this->output->writeln('<info>phUML has been updated.</info>');
62
        $this->output->writeln(sprintf(
63
            '<info>Current version is:</info> <options=bold>%s</options=bold>.',
64
            $newVersion
65
        ));
66
        $this->output->writeln(sprintf(
67
            '<info>Previous version was:</info> <options=bold>%s</options=bold>.',
68
            $oldVersion
69
        ));
70
    }
71
72
    public function noUpdateApplied(string $currentVersion): void
73
    {
74
        $this->output->writeln('<info>phUML is currently up to date.</info>');
75
        $this->output->writeln(sprintf(
76
            '<info>Current version is:</info> <options=bold>%s</options=bold>.',
77
            $currentVersion
78
        ));
79
    }
80
81
    public function error(Exception $exception): void
82
    {
83
        $this->output->writeln(sprintf('Error: <comment>%s</comment>', $exception->getMessage()));
84
    }
85
}
86