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 function str_repeat; |
12
|
|
|
use Yii; |
13
|
|
|
use yii\base\Module; |
14
|
|
|
use yii\console\Controller; |
15
|
|
|
use yii\helpers\Console; |
16
|
|
|
use yii\helpers\FileHelper; |
17
|
|
|
use function mb_strwidth; |
18
|
|
|
|
19
|
|
|
class DefaultController extends Controller |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var CodeStatModule|Module |
23
|
|
|
**/ |
24
|
|
|
public $module; |
25
|
|
|
|
26
|
|
|
public $color = true; |
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 actionIndex() |
37
|
|
|
{ |
38
|
|
|
$service = $this->module->statService; |
39
|
|
|
$summary = $service->makeStatistic($this->prepareFiles()); |
|
|
|
|
40
|
|
|
foreach ($summary as $name => &$row) { |
41
|
|
|
$row = ['Group' => $name] + $row; |
42
|
|
|
} |
43
|
|
|
$total = $service->summaryStatistic($summary); |
44
|
|
|
$total = ['Group' => 'Total'] + $total; |
45
|
|
|
$summary = $summary + [$total]; |
46
|
|
|
if ($this->color) { |
47
|
|
|
$summary = $this->colorize(array_values($summary)); |
48
|
|
|
} |
49
|
|
|
$this->headline('YII-2 Code Statistic', 'lightYellow'); |
50
|
|
|
$this->climate->table($summary); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function actionListFiles() |
54
|
|
|
{ |
55
|
|
|
Output::info('The following files will be processed accordingly module configuration'); |
56
|
|
|
$files = $this->prepareFiles(); |
57
|
|
|
Output::arrayList($files); |
58
|
|
|
Output::separator(); |
59
|
|
|
Output::info('Total: ' . count($files)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function colorize(array $summary) |
63
|
|
|
{ |
64
|
|
|
$colorized = []; |
65
|
|
|
foreach ($summary as $i => $row) { |
66
|
|
|
foreach ($row as $key => $value) { |
67
|
|
|
if ($key === 'Group') { |
68
|
|
|
$value = $this->wrap($value, 'yellow'); |
69
|
|
|
} |
70
|
|
|
if ($i == count($summary) - 1) { |
71
|
|
|
$value = $this->wrap($value, 'light_cyan'); |
72
|
|
|
} |
73
|
|
|
$key = $this->wrap($key, 'green'); |
74
|
|
|
$colorized[$i][$key] = (string)$value; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
return $colorized; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function wrap($string, $color) |
81
|
|
|
{ |
82
|
|
|
return "<bold><$color>$string</$color></bold>"; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function headline($string, $color) |
86
|
|
|
{ |
87
|
|
|
$this->climate->green()->border('=', 110)->$color()->tab(4)->out($string); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
protected function prepareFiles() |
94
|
|
|
{ |
95
|
|
|
$files = []; |
96
|
|
|
foreach ($this->module->scanTargets as $dir) { |
97
|
|
|
$files = array_merge(FileHelper::findFiles($dir, [ |
98
|
|
|
'only' => ['*.php'], |
99
|
|
|
'except' => $this->module->exceptTargets, |
100
|
|
|
'caseSensitive' => false, |
101
|
|
|
'recursive' => true, |
102
|
|
|
]), $files); |
103
|
|
|
} |
104
|
|
|
return $files; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths