ComposerWithoutDevDependenciesIsUpToDate::check()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace BeyondCode\SelfDiagnosis\Checks;
4
5
use BeyondCode\SelfDiagnosis\Composer;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Str;
8
9 View Code Duplication
class ComposerWithoutDevDependenciesIsUpToDate implements Check
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /** @var Composer */
12
    private $composer;
13
14
    /** @var string */
15
    private $output;
16
17
    public function __construct(Composer $composer)
18
    {
19
        $this->composer = $composer;
20
        $this->composer->setWorkingPath(base_path());
21
    }
22
23
    /**
24
     * The name of the check.
25
     *
26
     * @param array $config
27
     * @return string
28
     */
29
    public function name(array $config): string
30
    {
31
        return trans('self-diagnosis::checks.composer_without_dev_dependencies_is_up_to_date.name');
32
    }
33
34
    /**
35
     * Perform the actual verification of this check.
36
     *
37
     * @param array $config
38
     * @return bool
39
     */
40
    public function check(array $config): bool
41
    {
42
        $additionalOptions = Arr::get($config, 'additional_options', '');
43
44
        $this->output = $this->composer->installDryRun('--no-dev ' . $additionalOptions);
45
46
        return Str::contains($this->output, ['Nothing to install or update', 'Nothing to install, update or remove']);
47
    }
48
49
    /**
50
     * The error message to display in case the check does not pass.
51
     *
52
     * @param array $config
53
     * @return string
54
     */
55
    public function message(array $config): string
56
    {
57
        return trans('self-diagnosis::checks.composer_without_dev_dependencies_is_up_to_date.message', [
58
            'more' => $this->output,
59
        ]);
60
    }
61
}
62