InteractsWithComposer::composerRemovePackage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Cherrypulp\LaravelPackageGenerator\Commands\Traits;
4
5
use Cherrypulp\LaravelPackageGenerator\Exceptions\RuntimeException;
6
7
trait InteractsWithComposer
8
{
9
    /**
10
     * Run "composer dump-autoload".
11
     */
12
    protected function composerDumpAutoload()
13
    {
14
        $this->composerRunCommand('composer dump-autoload');
15
    }
16
17
    /**
18
     * Run "composer update $vendor/$package".
19
     *
20
     * @param string $vendor
21
     * @param string $package
22
     */
23
    protected function composerUpdatePackage($vendor, $package)
24
    {
25
        $this->composerRunCommand("composer update --ignore-platform-reqs $vendor/$package");
26
    }
27
28
    /**
29
     * Run "composer remove $vendor/$package".
30
     *
31
     * @param string $vendor
32
     * @param string $package
33
     */
34
    protected function composerRemovePackage($vendor, $package)
35
    {
36
        $this->composerRunCommand("composer remove --ignore-platform-reqs $vendor/$package");
37
    }
38
39
    /**
40
     * Run arbitrary composer command.
41
     *
42
     * @param $command
43
     */
44
    protected function composerRunCommand($command)
45
    {
46
        $this->info("Run \"$command\".");
0 ignored issues
show
Bug introduced by
It seems like info() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

46
        $this->/** @scrutinizer ignore-call */ 
47
               info("Run \"$command\".");
Loading history...
47
48
        if (defined("LARAVEL_PACKAGE_CLI_MODE")) {
49
            $command = "cd ".getcwd()." && ".$command;
50
        }
51
52
        $output = [];
53
        exec($command, $output, $returnStatusCode);
54
55
        if ($returnStatusCode !== 0) {
56
            throw RuntimeException::commandExecutionFailed($command, $returnStatusCode);
57
        }
58
59
        $this->info("\"$command\" was successfully ran.");
60
    }
61
}
62