ChangePackageVersionCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 31
c 3
b 1
f 0
dl 0
loc 56
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 41 4
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Filesystem\Filesystem;
10
use Symfony\Component\Process\Exception\ProcessFailedException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Proces...\ProcessFailedException 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...
11
use Symfony\Component\Process\Process;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Process\Process 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...
12
13
class ChangePackageVersionCommand extends Command
14
{
15
    protected function configure()
16
    {
17
        $this
18
            ->setName('ribsadmin:change-package-version')
19
            ->setDescription('Change a package version')
20
            ->addArgument(
21
                'package-name',
22
                InputArgument::REQUIRED,
23
                'Name of composer package to import with version (example : piou/piou/test-bundle:1.0.0)'
24
            )
25
        ;
26
    }
27
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        $fs = new Filesystem();
31
        $cd = "";
32
33
        if (!$fs->exists("composer.json") && $fs->exists("index.php")) {
34
            $cd = "cd .. && ";
35
        }
36
37
        $package_name = $input->getArgument('package-name');
38
39
        $process = Process::fromShellCommandline("echo Start composer require " . $package_name);
0 ignored issues
show
Bug introduced by
Are you sure $package_name of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

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

39
        $process = Process::fromShellCommandline("echo Start composer require " . /** @scrutinizer ignore-type */ $package_name);
Loading history...
40
        $process->run(function ($type, $buffer) {
41
            echo $buffer;
42
        });
43
44
        $process = Process::fromShellCommandline($cd . "chmod 777 composer.json");
45
        $process->run(function ($type, $buffer) {
46
            echo $buffer;
47
        });
48
49
        $process = Process::fromShellCommandline($cd . "composer require " . $package_name);
50
        $process->run(function ($type, $buffer) {
51
            echo $buffer;
52
        });
53
54
        if (!$process->isSuccessful()) {
55
            throw new ProcessFailedException($process);
56
        }
57
58
        $process = Process::fromShellCommandline($cd . "chmod 644 composer.json");
59
        $process->run(function ($type, $buffer) {
60
            echo $buffer;
61
        });
62
63
        $process = Process::fromShellCommandline("echo Change version of " . $package_name . " is finished.");
64
        $process->run(function ($type, $buffer) {
65
            echo $buffer;
66
        });
67
68
        return 0;
69
    }
70
}
71