ComposerWithDevDependenciesIsUpToDate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 53
loc 53
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A name() 4 4 1
A check() 8 8 1
A message() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 ComposerWithDevDependenciesIsUpToDate 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_with_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($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_with_dev_dependencies_is_up_to_date.message', [
58
            'more' => $this->output,
59
        ]);
60
    }
61
}
62