Passed
Branch 4.9 (cb955a)
by Mikhail
01:30
created

Ccg   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
dl 0
loc 36
c 1
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generate() 0 19 3
A __construct() 0 9 1
1
<?php
2
3
use exceptions\FileAlreadyExistsException;
4
use generators\AddonXml\AddonXmlGenerator;
5
use generators\Language\LanguageGenerator;
6
use generators\Readme\ReadmeGenerator;
7
use generators\FileGenerator;
8
use enums\Config as EnumConfig;
9
use terminal\Terminal;
10
use filesystem\Filesystem;
11
use mediators\GeneratorMediator;
12
13
/**
14
 * Enter point for all commands
15
 * @todo Find out a code splitting way for this class
16
 * It may be a several traits
17
 */
18
class Ccg
19
{
20
    private $config;
21
    private $terminal;
22
    private $filesystem;
23
24
    function __construct(
25
        Config              $config,
26
        Terminal            $terminal,
27
        Filesystem          $filesystem
28
    )
29
    {
30
        $this->config               = $config;
31
        $this->terminal             = $terminal;
32
        $this->filesystem           = $filesystem;
33
    }
34
35
    public function generate()
36
    {
37
        $generator  = $this->config->get(EnumConfig::$GENERATOR);
38
        $command    = $this->config->get(EnumConfig::$COMMAND) ?: 'index';
39
40
        try {
41
            $controllerClass = 'controllers\\' . $generator;
42
            $refl = new ReflectionClass($controllerClass);
43
            $controller = $refl->newInstanceArgs([
44
                $this->config,
45
                $this->terminal,
46
                $this->filesystem
47
            ]);
48
        } catch (\Exception $error) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
49
        }
50
        
51
        $controller->{$command}();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $controller does not seem to be defined for all execution paths leading up to this point.
Loading history...
52
53
        return $this;
54
    }
55
}
56