Completed
Push — cecil ( 66a45a )
by Arnaud
02:09
created

SelfUpdate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A processCommand() 0 18 3
1
<?php
2
/*
3
 * This file is part of the PHPoole/Cecil package.
4
 *
5
 * Copyright (c) Arnaud Ligny <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cecil\Command;
12
13
use Humbug\SelfUpdate\Updater;
14
15
class SelfUpdate extends AbstractCommand
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $version;
21
    /**
22
     * @var Updater
23
     */
24
    protected $updater;
25
26
    /**
27
     * @param mixed $version
28
     */
29
    public function __construct($version)
30
    {
31
        $this->version = $version;
32
33
        $this->updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
34
        /* @var $strategy \Humbug\SelfUpdate\Strategy\GithubStrategy */
35
        $strategy = $this->updater->getStrategy();
36
        $strategy->setPackageName('phpoole/cecil');
37
        $strategy->setPharName('cecil.phar');
38
        $strategy->setCurrentLocalVersion($this->version);
39
        $strategy->setStability('any');
40
    }
41
42
    public function processCommand()
43
    {
44
        try {
45
            echo "\rChecks for updates...";
46
            $result = $this->updater->update();
47
            if ($result) {
48
                $new = $this->updater->getNewVersion();
49
                $old = $this->updater->getOldVersion();
50
                printf("\rUpdated from %s to %s.\n", $old, $new);
51
                exit(0);
52
            }
53
            printf("\rYou are already using last version (%s).\n", $this->version);
54
            exit(0);
55
        } catch (\Exception $e) {
56
            echo $e->getMessage();
57
            exit(1);
58
        }
59
    }
60
}
61