Completed
Push — master ( dde429...22637e )
by Andrii
20:00
created

Application::main()   B

Complexity

Conditions 5
Paths 17

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
ccs 0
cts 25
cp 0
rs 8.439
cc 5
eloc 17
nc 17
nop 0
crap 30
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\base;
13
14
use Exception;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
use yii\base\InvalidParamException;
18
use yii\console\Exception as ConsoleException;
19
use yii\base\Module;
20
use yii\base\ViewContextInterface;
21
use yii\helpers\ArrayHelper;
22
23
/**
24
 * The Application.
25
 */
26
class Application extends \yii\console\Application implements ViewContextInterface
27
{
28
    public $isInit = false;
29
30
    protected $_viewPath;
31
32
    public static function main()
33
    {
34
        try {
35
            Yii::setLogger(Yii::createObject('hidev\base\Logger'));
36
            $config = ArrayHelper::merge(
37
                require dirname(dirname(__DIR__)) . '/.hidev/vendor/yiisoft/yii2-extraconfig.php',
38
                require dirname(dirname(__DIR__)) . '/vendor/yiisoft/yii2-extraconfig.php',
39
                require __DIR__ . '/config.php'
40
            );
41
            # var_dump($config); die();
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
            foreach ($config['aliases'] as $name => $alias) {
43
                Yii::setAlias($name, $alias);
44
            }
45
            $exitCode = (new static($config))->run();
46
        } catch (Exception $e) {
47
            if ($e instanceof InvalidParamException || $e instanceof ConsoleException) {
48
                Yii::error($e->getMessage());
49
                $exitCode = 1;
50
            } else {
51
                throw $e;
52
            }
53
        }
54
55
        return $exitCode;
56
    }
57
58
    /*public function getViewPath()
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
59
    {
60
        if ($this->_viewPath === null) {
61
            $this->_viewPath = Yii::getAlias('@app/views');
62
        }
63
64
        return $this->_viewPath;
65
    }*/
66
67
    public function createControllerByID($id)
68
    {
69
        if (!$this->get('config')->hasGoal($id)) {
70
            var_dump("CANT RUN GOAL: $id");
0 ignored issues
show
Security Debugging Code introduced by
var_dump("CANT RUN GOAL: {$id}"); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
71
            #var_dump(ArrayHelper::toArray($this->get('config')));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72
            throw new InvalidConfigException("can't run goal '$id'");
73
        }
74
75
        #var_dump( $this->get('config')->get($id) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
76
        return $this->get('config')->get($id);
77
    }
78
79
    public function runRequest($string)
80
    {
81
        $request = Yii::createObject([
82
            'class'  => 'hidev\base\Request',
83
            'params' => array_filter(explode(' ', $string)),
84
        ]);
85
86
        return $this->handleRequest($request);
87
    }
88
89
    public function runAction($route, $params = [])
90
    {
91
        try {
92
            return Module::runAction($route, $params);
93
        } catch (InvalidRouteException $e) {
0 ignored issues
show
Bug introduced by
The class hidev\base\InvalidRouteException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
94
            throw new Exception("Unknown command \"$route\".", 0, $e);
95
        }
96
    }
97
}
98