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 ( ab57ef...932a6b )
by Steeven
02:30
created

Migration::execute()   B

Complexity

Conditions 8
Paths 41

Size

Total Lines 106
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 77
c 1
b 0
f 1
nc 41
nop 0
dl 0
loc 106
rs 7.2573

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 Migration
23
 *
24
 * @package O2System\Framework\Cli\Commanders\Make
25
 */
26
class Migration extends Make
27
{
28
    /**
29
     * Migration::$commandDescription
30
     *
31
     * Command description.
32
     *
33
     * @var string
34
     */
35
    protected $commandDescription = 'CLI_MAKE_MIGRATION_DESC';
36
37
    /**
38
     * Migration::$optionFileVersion
39
     *
40
     * @var string
41
     */
42
    protected $optionFileVersion = 'v.0.0.0';
43
44
    /**
45
     * Migration::$optionNoSql
46
     *
47
     * @var bool
48
     */
49
    protected $optionNoSql = false;
50
51
    // ------------------------------------------------------------------------
52
53
    /**
54
     * Migration::optionFileVersion
55
     */
56
    public function optionFileVersion($version)
57
    {
58
        $this->optionFileVersion = $version;
59
    }
60
61
    // ------------------------------------------------------------------------
62
63
    /**
64
     * Migration::optionPath
65
     *
66
     * @param string $path
67
     */
68
    public function optionPath($path)
69
    {
70
        $this->optionPath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
71
    }
72
73
    // ------------------------------------------------------------------------
74
75
    /**
76
     * Migration::optionNoSql
77
     */
78
    public function optionNoSql()
79
    {
80
        $this->optionNoSql = true;
81
    }
82
83
    // ------------------------------------------------------------------------
84
85
    /**
86
     * Migration::execute
87
     */
88
    public function execute()
89
    {
90
        $this->__callOptions();
91
92
        if (empty($this->optionFilename)) {
93
            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

93
            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...
94
                (new Format())
95
                    ->setContextualClass(Format::DANGER)
96
                    ->setString(language()->getLine('CLI_MAKE_MIGRATION_E_FILENAME'))
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
        $className = studlycase($this->optionFilename);
104
105
        if(empty($this->optionFileVersion)) {
106
            $filename = date('YmdHis') . '_' . underscore($this->optionFilename);
107
        } else {
108
            $filename = $this->optionFileVersion . '_' . underscore($this->optionFilename);
109
        }
110
111
        $filePath = PATH_DATABASE . 'migrations' . DIRECTORY_SEPARATOR;
112
113
        if( ! empty($this->optionPath) ) {
114
            $filePath = $filePath . $this->optionPath;
115
        }
116
117
        $filePath = $filePath . $filename;
118
119
        $fileDirectory = dirname($filePath) . DIRECTORY_SEPARATOR;
120
121
        if ( ! is_dir($fileDirectory)) {
122
            mkdir($fileDirectory, 0777, true);
123
        }
124
125
        if (is_file($filePath)) {
126
            output()->write(
127
                (new Format())
128
                    ->setContextualClass(Format::DANGER)
129
                    ->setString(language()->getLine('CLI_MAKE_MIGRATION_E_EXISTS', [$filePath]))
130
                    ->setNewLinesAfter(1)
131
            );
132
133
            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...
134
        }
135
136
        $vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$vars was never initialized. Although not strictly required by PHP, it is generally a good practice to add $vars = array(); before regardless.
Loading history...
137
        $vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\Sql\Migration';
138
139
        if($this->optionNoSql) {
140
            $vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\NoSql\Migration';
141
        }
142
143
        $vars[ 'CLASS' ] = $className;
144
        $vars[ 'FILEPATH' ] = $filePath;
145
146
        $phpTemplate = <<<PHPTEMPLATE
147
<?php
148
/**
149
 * Created by O2System Framework File Generator.
150
 * DateTime: CREATE_DATETIME
151
 */
152
153
// ------------------------------------------------------------------------
154
155
use BASE_MIGRATION
156
157
/**
158
 * Class CLASS
159
 */
160
class CLASS extends Migration
161
{
162
    /**
163
     * CLASS::up
164
     */
165
    public function up()
166
    {
167
        // TODO: Change the autogenerated stub
168
    }
169
    
170
    // ------------------------------------------------------------------------
171
    
172
    /**
173
     * CLASS::down
174
     */
175
    public function down()
176
    {
177
        // TODO: Change the autogenerated stub
178
    }
179
}
180
PHPTEMPLATE;
181
182
        $fileContent = str_replace(array_keys($vars), array_values($vars), $phpTemplate);
183
        file_put_contents($filePath, $fileContent);
184
185
        if (is_file($filePath)) {
186
            output()->write(
187
                (new Format())
188
                    ->setContextualClass(Format::SUCCESS)
189
                    ->setString(language()->getLine('CLI_MAKE_MIGRATION_S_MAKE', [$filePath]))
190
                    ->setNewLinesAfter(1)
191
            );
192
193
            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...
194
        }
195
    }
196
}