Completed
Pull Request — master (#60)
by
unknown
177:15
created

ComposerWithoutDevDependenciesIsUpToDate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 53
loc 53
ccs 13
cts 13
cp 1
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
7 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...
8
{
9
    /** @var Composer */
10
    private $composer;
11
12
    /** @var string */
13
    private $output;
14
15 20
    public function __construct(Composer $composer)
16
    {
17 20
        $this->composer = $composer;
18 20
        $this->composer->setWorkingPath(base_path());
19 20
    }
20
21
    /**
22
     * The name of the check.
23
     *
24
     * @param array $config
25
     * @return string
26
     */
27 4
    public function name(array $config): string
28
    {
29 4
        return trans('self-diagnosis::checks.composer_without_dev_dependencies_is_up_to_date.name');
30
    }
31
32
    /**
33
     * Perform the actual verification of this check.
34
     *
35
     * @param array $config
36
     * @return bool
37
     */
38 12
    public function check(array $config): bool
39
    {
40 12
        $additionalOptions = array_get($config, 'additional_options', '');
41
42 12
        $this->output = $this->composer->installDryRun('--no-dev ' . $additionalOptions);
43
44 12
        return str_contains($this->output, 'Nothing to install or update');
45
    }
46
47
    /**
48
     * The error message to display in case the check does not pass.
49
     *
50
     * @param array $config
51
     * @return string
52
     */
53 4
    public function message(array $config): string
54
    {
55 4
        return trans('self-diagnosis::checks.composer_without_dev_dependencies_is_up_to_date.message', [
56 4
            'more' => $this->output,
57
        ]);
58
    }
59
}
60