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); |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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 |
|
|
|
|
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
|
|
|
|
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.