|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by solly [18.10.17 4:41] |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace insolita\codestat\controllers; |
|
7
|
|
|
|
|
8
|
|
|
use insolita\codestat\CodeStatModule; |
|
9
|
|
|
use insolita\codestat\helpers\Output; |
|
10
|
|
|
use League\CLImate\CLImate; |
|
11
|
|
|
use yii\base\Module; |
|
12
|
|
|
use yii\console\Controller; |
|
13
|
|
|
|
|
14
|
|
|
class DefaultController extends Controller |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var CodeStatModule|Module |
|
18
|
|
|
**/ |
|
19
|
|
|
public $module; |
|
20
|
|
|
|
|
21
|
|
|
public $color = true; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* If true will output files with failed reads by Reflection class |
|
25
|
|
|
*/ |
|
26
|
|
|
public $showErrors = false; |
|
27
|
|
|
|
|
28
|
|
|
protected $climate; |
|
29
|
|
|
|
|
30
|
|
|
public function __construct($id, Module $module, CLImate $CLImate, array $config = []) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->climate = $CLImate; |
|
33
|
|
|
parent::__construct($id, $module, $config); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function options($actionID) |
|
37
|
|
|
{ |
|
38
|
|
|
return array_merge(parent::options($actionID) , ['showErrors']); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function actionIndex() |
|
42
|
|
|
{ |
|
43
|
|
|
$service = $this->module->statService; |
|
44
|
|
|
$summary = $service->makeStatistic($this->module->prepareFiles()); |
|
|
|
|
|
|
45
|
|
|
foreach ($summary as $name => &$row) { |
|
46
|
|
|
$row = ['Group' => $name] + $row; |
|
47
|
|
|
} |
|
48
|
|
|
$total = $service->summaryStatistic($summary); |
|
49
|
|
|
$total = ['Group' => 'Total'] + $total; |
|
50
|
|
|
$summary = $summary + [$total]; |
|
51
|
|
|
if ($this->color) { |
|
52
|
|
|
$summary = $this->colorize(array_values($summary)); |
|
53
|
|
|
} |
|
54
|
|
|
$this->headline('YII-2 Code Statistic', 'lightYellow'); |
|
55
|
|
|
$this->climate->table($summary); |
|
56
|
|
|
|
|
57
|
|
|
if($this->showErrors === true){ |
|
58
|
|
|
$this->headline('Failed for resolve', 'lightYellow'); |
|
59
|
|
|
$this->climate->table($service->errorList()); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function actionListFiles() |
|
64
|
|
|
{ |
|
65
|
|
|
Output::info('The following files will be processed accordingly module configuration'); |
|
66
|
|
|
$files = $this->module->prepareFiles(); |
|
67
|
|
|
Output::arrayList($files); |
|
68
|
|
|
Output::separator(); |
|
69
|
|
|
Output::info('Total: ' . count($files)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
protected function colorize(array $summary) |
|
73
|
|
|
{ |
|
74
|
|
|
$colorized = []; |
|
75
|
|
|
foreach ($summary as $i => $row) { |
|
76
|
|
|
foreach ($row as $key => $value) { |
|
77
|
|
|
if ($key === 'Group') { |
|
78
|
|
|
$value = $this->wrap($value, 'yellow'); |
|
79
|
|
|
} |
|
80
|
|
|
if ($i == count($summary) - 1) { |
|
81
|
|
|
$value = $this->wrap($value, 'light_cyan'); |
|
82
|
|
|
} |
|
83
|
|
|
$key = $this->wrap($key, 'green'); |
|
84
|
|
|
$colorized[$i][$key] = (string)$value; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
return $colorized; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function wrap($string, $color) |
|
91
|
|
|
{ |
|
92
|
|
|
return "<bold><$color>$string</$color></bold>"; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
protected function headline($string, $color) |
|
96
|
|
|
{ |
|
97
|
|
|
$this->climate->green()->border('=', 110)->$color()->tab(4)->out($string); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
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.