Completed
Push — master ( 9a51b8...d4f476 )
by Nicolas
03:19
created

Hydrate   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 50.85 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 30
loc 59
ccs 32
cts 32
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getProcessor() 0 4 1
A launchConfigurationAction() 0 9 2
A warnForUnusedVariables() 16 16 2
A warnForUnvaluedVariables() 14 14 2

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
declare(strict_types = 1);
4
5
namespace Karma\Console;
6
7
use Karma\ConfigurableProcessor;
8
use Karma\Application;
9
use Karma\Hydrator;
10
11
class Hydrate extends ConfigureActionCommand
12
{
13 36
    public function __construct(Application $app)
14
    {
15 36
        parent::__construct(
16 36
            $app,
17 36
            'hydrate',
18 36
            'Hydrate dist files',
19 36
            'Hydrate'
20
        );
21 36
    }
22
23 10
    protected function getProcessor(): ConfigurableProcessor
24
    {
25 10
        return $this->app['hydrator'];
26
    }
27
28 10
    protected function launchConfigurationAction(ConfigurableProcessor $processor): void
29
    {
30 10
        if($processor instanceof Hydrator)
0 ignored issues
show
Bug introduced by
The class Karma\Hydrator does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
31
        {
32 10
            $processor->hydrate($this->environment);
33 10
            $this->warnForUnusedVariables($processor);
34 10
            $this->warnForUnvaluedVariables($processor);
35
        }
36 10
    }
37
38 10 View Code Duplication
    private function warnForUnusedVariables(Hydrator $processor): void
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40 10
        $unusedVariables = $processor->getUnusedVariables();
41
42 10
        if(! empty($unusedVariables))
43
        {
44 8
            $logger = $this->app['logger'];
45
46 8
            $logger->warning('You have unused variables : you should remove them or check if you have not mispelled them');
47
48 8
            $logger->warning(sprintf(
49 8
                'Unused variables : %s',
50 8
                implode(', ', $unusedVariables)
51
            ));
52
        }
53 10
    }
54
55 10 View Code Duplication
    private function warnForUnvaluedVariables(Hydrator $processor): void
0 ignored issues
show
Duplication introduced by
This method 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...
56
    {
57 10
        $unvaluedVariables = $processor->getUnvaluedVariables();
58
59 10
        if(! empty($unvaluedVariables))
60
        {
61 1
            $logger = $this->app['logger'];
62
63 1
            $logger->warning(sprintf(
64 1
                'Missing values for variables : %s (TODO markers found)',
65 1
                implode(', ', $unvaluedVariables)
66
            ));
67
        }
68 10
    }
69
}
70