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

Hydrate::warnForUnusedVariables()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 9
cts 9
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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