InteractsWithComposer::composerDumpAutoload()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Blok\LaravelPackageGenerator\Commands\Traits;
4
5
use Blok\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
        $output = [];
49
        exec($command, $output, $returnStatusCode);
50
51
        if ($returnStatusCode !== 0) {
52
            throw RuntimeException::commandExecutionFailed($command, $returnStatusCode);
53
        }
54
55
        $this->info("\"$command\" was successfully ran.");
56
    }
57
}
58