Passed
Push — master ( 6cab0f...4aee41 )
by Insolita
01:43
created

DefaultController::options()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
    protected $climate;
24
    
25
    public function __construct($id, Module $module, CLImate $CLImate, array $config = [])
26
    {
27
        $this->climate = $CLImate;
28
        parent::__construct($id, $module, $config);
29
    }
30
31
    public function actionIndex($showErrors = false)
32
    {
33
        $service = $this->module->statService;
34
        $summary = $service->makeStatistic($this->module->prepareFiles());
0 ignored issues
show
Bug introduced by
The method makeStatistic() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        /** @scrutinizer ignore-call */ 
35
        $summary = $service->makeStatistic($this->module->prepareFiles());

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...
35
        foreach ($summary as $name => &$row) {
36
            $row = ['Group' => $name] + $row;
37
        }
38
        $total = $service->summaryStatistic($summary);
39
        $total = ['Group' => 'Total'] + $total;
40
        $summary = $summary + [$total];
41
        if ($this->color) {
42
            $summary = $this->colorize(array_values($summary));
43
        }
44
        $this->headline('YII-2 Code Statistic', 'lightYellow');
45
        $this->climate->table($summary);
46
47
        if($showErrors === true){
48
            $this->headline('Failed for resolve', 'lightYellow');
49
            $this->climate->table($service->errorList());
0 ignored issues
show
Bug introduced by
The method errorList() does not exist on insolita\codestat\lib\co...odestatServiceInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to insolita\codestat\lib\co...odestatServiceInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
            $this->climate->table($service->/** @scrutinizer ignore-call */ errorList());
Loading history...
50
        }
51
    }
52
    
53
    public function actionListFiles()
54
    {
55
        Output::info('The following files will be processed accordingly module configuration');
56
        $files = $this->module->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