Passed
Push — master ( 7f4746...b03b6b )
by Nicolaas
02:04
created

Composer::ClearCache()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Sunnysideup\UpgradeToSilverstripe4\Tasks\Helpers;
4
5
use Sunnysideup\UpgradeToSilverstripe4\Traits\HelperInst;
6
7
class Composer
8
{
9
    use HelperInst;
10
11
    protected $defaultOptions = '';
12
13
    public function DumpAutoload(): self
14
    {
15
        $this->mu()->execMe(
16
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

16
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
Bug introduced by
The method getWebRootDirLocation() does not exist on Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

16
            $this->mu()->/** @scrutinizer ignore-call */ getWebRootDirLocation(),
Loading history...
17
            'composer dumpautoload --no-interaction',
18
            'run composer dumpautoload',
19
            false
20
        );
21
22
        return $this;
23
    }
24
25
    public function ClearCache(): self
26
    {
27
        $this->mu()->execMe(
28
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

28
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
29
            'composer clear-cache --no-interaction',
30
            'clear composer cache',
31
            false
32
        );
33
34
        return $this;
35
    }
36
37
    public function RequireGlobal(string $package, ?string $version = '', ?bool $devOnly = false, ?string $options = ''): self
38
    {
39
        return $this->requireAny($package, $version, $devOnly, $options, true);
40
    }
41
42
    public function Require(string $package, ?string $version = '', ?string $options = ''): self
43
    {
44
        return $this->requireAny($package, $version, false, $options, false);
45
    }
46
47
    public function RequireDev(string $package, ?string $version = '', ?string $options = ''): self
48
    {
49
        return $this->requireAny($package, $version, true, $options, false);
50
    }
51
52
    public function RemoveDev(string $package): self
53
    {
54
        return $this->Remove($package, true);
55
    }
56
57
    public function Remove(string $package, ?bool $devOnly = false): self
58
    {
59
        $devFlag = $devOnly ? '--dev' : '';
60
        $this->mu()->execMe(
61
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

61
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
62
            'composer remove ' . $package . ' ' . $devFlag. ' --no-interaction',
63
            'running composer remove ' . $package . ' ' . $devFlag,
64
            false
65
        );
66
67
        return $this;
68
    }
69
70
    protected function requireAny(string $package, ?string $version = '', ?bool $devOnly = false, ?string $options = '', ?bool $isGlobal = false): self
71
    {
72
        $devFlag = $devOnly ? '--dev' : '';
73
        if (! $options) {
74
            $options = $this->defaultOptions;
75
        }
76
        if ($version) {
77
            $version = ':' . $version;
78
        }
79
        $globalPhrase = '';
80
        if ($isGlobal) {
81
            $globalPhrase = 'global';
82
        }
83
        $this->mu()->execMe(
84
            $this->mu()->getWebRootDirLocation(),
0 ignored issues
show
Bug introduced by
It seems like $this->mu()->getWebRootDirLocation() can also be of type Sunnysideup\UpgradeToSilverstripe4\ModuleUpgrader and null; however, parameter $newDir of Sunnysideup\UpgradeToSil...oduleUpgrader::execMe() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

84
            /** @scrutinizer ignore-type */ $this->mu()->getWebRootDirLocation(),
Loading history...
85
            'composer ' . $globalPhrase . ' require ' . $package . $version . ' ' . $devFlag . ' ' . $options. ' --no-interaction',
86
            'running composer require ' . $package . $version . ' ' . $devFlag . ' ' . $options,
87
            false
88
        );
89
90
        return $this;
91
    }
92
}
93