GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a1835d...10e84a )
by
unknown
02:48
created

Plugin::execute()   B

Complexity

Conditions 7
Paths 21

Size

Total Lines 80
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 53
nc 21
nop 0
dl 0
loc 80
rs 8.0921
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Framework\Cli\Commanders\Make;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Framework\Cli\Commanders\Make;
19
use O2System\Kernel\Cli\Writers\Format;
20
21
/**
22
 * Class Plugin
23
 *
24
 * @package O2System\Framework\Cli\Commanders\Make
25
 */
26
class Plugin extends Make
27
{
28
    /**
29
     * Plugin::$optionName
30
     *
31
     * @var string
32
     */
33
    public $optionName;
34
35
    /**
36
     * Plugin::$commandDescription
37
     *
38
     * Command description.
39
     *
40
     * @var string
41
     */
42
    protected $commandDescription = 'CLI_MAKE_MODULE_DESC';
43
44
    // ------------------------------------------------------------------------
45
46
    /**
47
     * Plugin::optionName
48
     *
49
     * @param string $name
50
     */
51
    public function optionName($name)
52
    {
53
        if (empty($this->optionPath)) {
54
            $this->optionPath = PATH_APP . 'Modules' . DIRECTORY_SEPARATOR;
55
        }
56
57
        $this->optionName = $name;
58
    }
59
60
    // ------------------------------------------------------------------------
61
62
    /**
63
     * Plugin::execute
64
     */
65
    public function execute()
66
    {
67
        parent::execute();
68
69
        if (empty($this->optionName)) {
70
            output()->write(
0 ignored issues
show
Bug introduced by
The method write() does not exist on O2System\Kernel\Http\Output. ( Ignorable by Annotation )

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

70
            output()->/** @scrutinizer ignore-call */ write(

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...
71
                (new Format())
72
                    ->setContextualClass(Format::DANGER)
73
                    ->setString(language()->getLine('CLI_MAKE_MODULE_E_NAME'))
74
                    ->setNewLinesAfter(1)
75
            );
76
77
            exit(EXIT_ERROR);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
78
        }
79
80
        $moduleType = empty($this->moduleType)
0 ignored issues
show
Bug Best Practice introduced by
The property moduleType does not exist on O2System\Framework\Cli\Commanders\Make\Plugin. Since you implemented __get, consider adding a @property annotation.
Loading history...
81
            ? 'Plugins'
82
            : ucfirst(plural($this->moduleType));
0 ignored issues
show
Bug introduced by
It seems like $this->moduleType can also be of type O2System\Framework\Containers\Models and O2System\Framework\Models\NoSql\Model and O2System\Framework\Models\Sql\Model; however, parameter $string of plural() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

82
            : ucfirst(plural(/** @scrutinizer ignore-type */ $this->moduleType));
Loading history...
83
84
        if (strpos($this->optionPath, $moduleType) === false) {
85
            $modulePath = $this->optionPath . $moduleType . DIRECTORY_SEPARATOR . $this->optionName . DIRECTORY_SEPARATOR;
86
        } else {
87
            $modulePath = $this->optionPath . $this->optionName . DIRECTORY_SEPARATOR;
88
        }
89
90
        if ( ! is_dir($modulePath)) {
91
            mkdir($modulePath, 0777, true);
92
        } else {
93
            output()->write(
94
                (new Format())
95
                    ->setContextualClass(Format::DANGER)
96
                    ->setString(language()->getLine('CLI_MAKE_PLUGIN_E_EXISTS', [$modulePath]))
97
                    ->setNewLinesAfter(1)
98
            );
99
100
            exit(EXIT_ERROR);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
101
        }
102
103
        $jsonProperties[ 'name' ] = readable(
0 ignored issues
show
Comprehensibility Best Practice introduced by
$jsonProperties was never initialized. Although not strictly required by PHP, it is generally a good practice to add $jsonProperties = array(); before regardless.
Loading history...
104
            pathinfo($modulePath, PATHINFO_FILENAME),
105
            true
106
        );
107
108
        if (empty($this->namespace)) {
109
            @list($moduleDirectory, $moduleName) = explode($moduleType, dirname($modulePath));
110
            $namespace = loader()->getDirNamespace($moduleDirectory) .
111
                $moduleType . '\\' . prepare_class_name(
112
                    $this->optionName
113
                ) . '\\';
114
        } else {
115
            $namespace = $this->namespace;
116
            $jsonProperties[ 'namespace' ] = rtrim($namespace, '\\') . '\\';
117
        }
118
119
        $jsonProperties[ 'created' ] = date('d M Y');
120
121
        loader()->addNamespace($namespace, $modulePath);
122
123
        $fileContent = json_encode($jsonProperties, JSON_PRETTY_PRINT);
124
125
        $filePath = $modulePath . strtolower(singular($moduleType)) . '.json';
126
127
        file_put_contents($filePath, $fileContent);
128
129
        $this->optionPath = $modulePath;
130
        $this->optionFilename = prepare_filename($this->optionName) . '.php';
131
132
        (new Controller())
133
            ->optionPath($this->optionPath)
134
            ->optionFilename($this->optionFilename);
135
136
        if (is_dir($modulePath)) {
137
            output()->write(
138
                (new Format())
139
                    ->setContextualClass(Format::SUCCESS)
140
                    ->setString(language()->getLine('CLI_MAKE_PLUGIN_S_MAKE', [$modulePath]))
141
                    ->setNewLinesAfter(1)
142
            );
143
144
            exit(EXIT_SUCCESS);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
145
        }
146
    }
147
}