Completed
Pull Request — master (#104)
by Nicolas
03:17
created

Hydrate   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 42.25 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 83.78%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 30
loc 71
ccs 31
cts 37
cp 0.8378
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getProcessor() 0 4 1
A launchConfigurationAction() 0 7 1
A warnForUnusedVariables() 16 16 2
A warnForUnvaluedVariables() 14 14 2
A hydrationStats() 0 13 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
        $processor->hydrate($this->environment);
0 ignored issues
show
Bug introduced by
The method hydrate() does not seem to exist on object<Karma\ConfigurableProcessor>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31 10
        $this->warnForUnusedVariables($processor);
32 10
        $this->warnForUnvaluedVariables($processor);
33
    //    $this->hydrationStats($processor);
34 10
    }
35
36 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...
37
    {
38 10
        $unusedVariables = $processor->getUnusedVariables();
39
40 10
        if(! empty($unusedVariables))
41
        {
42 8
            $logger = $this->app['logger'];
43
44 8
            $logger->warning('You have unused variables : you should remove them or check if you have not mispelled them');
45
46 8
            $logger->warning(sprintf(
47 8
                'Unused variables : %s',
48 8
                implode(', ', $unusedVariables)
49
            ));
50
        }
51 10
    }
52
53 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...
54
    {
55 10
        $unvaluedVariables = $processor->getUnvaluedVariables();
56
57 10
        if(! empty($unvaluedVariables))
58
        {
59 1
            $logger = $this->app['logger'];
60
61 1
            $logger->warning(sprintf(
62 1
                'Missing values for variables : %s (TODO markers found)',
63 1
                implode(', ', $unvaluedVariables)
64
            ));
65
        }
66 10
    }
67
68
    private function hydrationStats(Hydrator $processor): void
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
69
    {
70
        foreach($processor->hydratedFiles() as $file => $nbVariables)
71
        {
72
            $logger = $this->app['logger'];
73
74
            $logger->debug(sprintf(
75
                '%-30s [%2d]',
76
                $file,
77
                $nbVariables
78
            ));
79
        }
80
    }
81
}
82