Updater   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 4
eloc 12
c 5
b 1
f 0
dl 0
loc 36
rs 10
ccs 0
cts 12
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A update() 0 12 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Updater;
15
16
use Humbug\SelfUpdate\Updater as PharUpdater;
17
use Illuminate\Console\OutputStyle;
18
19
/**
20
 * @internal
21
 */
22
final class Updater
23
{
24
    /**
25
     * The base updater.
26
     *
27
     * @var \Humbug\SelfUpdate\Updater
28
     */
29
    private $updater;
30
31
    /**
32
     * Updater constructor.
33
     *
34
     * @param \Humbug\SelfUpdate\Updater $updater
35
     */
36
    public function __construct(PharUpdater $updater)
37
    {
38
        $this->updater = $updater;
39
    }
40
41
    /**
42
     * @param \Illuminate\Console\OutputStyle
43
     *
44
     * @return void
45
     */
46
    public function update(OutputStyle $output): void
47
    {
48
        $result = $this->updater->update();
49
50
        if ($result) {
51
            $output->success(sprintf('Updated from version %s to %s.', $this->updater->getOldVersion(),
52
                $this->updater->getNewVersion()));
53
            exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
54
        } elseif (! $this->updater->getNewVersion()) {
55
            $output->success('There are no stable versions available.');
56
        } else {
57
            $output->success('You have the latest version installed.');
58
        }
59
    }
60
}
61