UpdateCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 9 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: nicolas
5
 * Date: 07/04/17
6
 * Time: 10:46
7
 */
8
9
namespace Devgiants\Command;
10
11
12
use Herrera\Phar\Update\Manager;
0 ignored issues
show
Bug introduced by
The type Herrera\Phar\Update\Manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Herrera\Phar\Update\Manifest;
0 ignored issues
show
Bug introduced by
The type Herrera\Phar\Update\Manifest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use KevinGH\Version\Version;
0 ignored issues
show
Bug introduced by
The type KevinGH\Version\Version was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class UpdateCommand extends Command
20
{
21
    const ROOT_URL = "https://devgiants.github.io/livebox/";
22
    const MANIFEST_FILE_URL = self::ROOT_URL . 'manifest.json';
23
    const DOWNLOAD_FOLDER = self::ROOT_URL . 'downloads';
24
25
    /**
26
     * @inheritdoc
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('self-update')
32
            ->setDescription('Updates livebox.phar to the latest version')
33
        ;
34
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    protected function execute(InputInterface $input, OutputInterface $output)
40
    {
41
        $manager = new Manager(Manifest::loadFile(self::MANIFEST_FILE_URL));
42
        $previousVersion = $this->getApplication()->getVersion();
43
44
        if($manager->update($this->getApplication()->getVersion(), true)) {
45
            $output->writeln("<fg=black;bg=green>Application was successfully updated from {$previousVersion} to {$manager->getManifest()->findRecent(Version::create($previousVersion))->getVersion()->__toString()}</>");
46
        } else {
47
            $output->writeln("<fg=black;bg=green>Application is up-to-date ({$previousVersion})</>");
48
        }
49
    }
50
}