Completed
Push — master ( f6cc4f...20183c )
by Andrii
03:46
created

src/console/DumpController.php (5 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\console;
12
13
use Symfony\Component\Yaml\Yaml;
14
use Yii;
15
16
/**
17
 * Dump available definitions: components, controllers, aliases.
18
 */
19
class DumpController extends \yii\console\Controller
20
{
21
    public $defaultAction = 'component';
22
23
    /**
24
     * Dump defined components.
25
     * @param string $name component name
26
     */
27 View Code Duplication
    public function actionComponent($name = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $data = Yii::$app->getComponents();
30
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
31
            if (empty($data[$name])) {
32
                Yii::error("'$name' not defined");
33
34
                return;
35
            }
36
            $data = [$name => $data[$name]];
37
        }
38
        echo Yaml::dump($data, 4);
39
    }
40
41
    /**
42
     * Dump defined controllers.
43
     * @param string $name controller name
44
     */
45 View Code Duplication
    public function actionController($name = null)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $data = Yii::$app->controllerMap;
48
        if ($name) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $name of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
49
            if (empty($data[$name])) {
50
                Yii::error("'$name' not defined");
51
52
                return;
53
            }
54
            $data = [$name => $data[$name]];
55
        }
56
        echo Yaml::dump($data, 4);
57
    }
58
59
    /**
60
     * Dump defined aliases.
61
     * @param string $alias alias to resolve
62
     */
63
    public function actionAlias($alias = null)
64
    {
65
        $data = Yii::$aliases;
66
        if ($alias) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $alias of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
67
            $dest = Yii::getAlias($alias, false);
68
            if (empty($dest)) {
69
                Yii::error("'$alias' not defined");
70
71
                return;
72
            }
73
            $data = [$alias => $dest];
74
        }
75
        echo Yaml::dump($data, 4);
76
    }
77
}
78