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 ( 874a03...659838 )
by Steeven
02:24
created

Build::optionMain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System PHP 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;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Kernel\Cli\Writers\Format;
19
use O2System\Framework\Cli\Commander;
20
21
/**
22
 * Class Build
23
 * @package O2System\Framework\Cli\Commanders
24
 */
25
class Build extends Commander
26
{
27
    /**
28
     * Build::$commandVersion
29
     *
30
     * Command version.
31
     *
32
     * @var string
33
     */
34
    protected $commandVersion = '1.0.0';
35
36
    /**
37
     * Build::$commandDescription
38
     *
39
     * Command description.
40
     *
41
     * @var string
42
     */
43
    protected $commandDescription = 'CLI_BUILD_DESC';
44
45
    /**
46
     * Build::$commandOptions
47
     *
48
     * Command options.
49
     *
50
     * @var array
51
     */
52
    protected $commandOptions = [
53
        'filename'   => [
54
            'description' => 'CLI_BUILD_FILENAME_HELP',
55
            'required'    => false,
56
        ],
57
        'main' => [
58
            'description' => 'CLI_BUILD_MAIN_HELP',
59
            'required'    => false,
60
        ],
61
        'force' => [
62
            'description' => 'CLI_BUILD_FORCE_HELP',
63
            'required'    => false,
64
        ],
65
    ];
66
67
    /**
68
     * Build::$optionFilename
69
     *
70
     * Build filename.
71
     *
72
     * @var string
73
     */
74
    protected $optionFilename;
75
76
    /**
77
     * Build::$optionMain
78
     *
79
     * Build main script.
80
     *
81
     * @var string
82
     */
83
    protected $optionMain;
84
85
    /**
86
     * Build::optionFilename
87
     *
88
     * @param string $name
89
     */
90
    public function optionFilename($filename)
91
    {
92
        $this->optionFilename = str_replace('.phar', '', $filename) . '.phar';
93
    }
94
95
    // ------------------------------------------------------------------------
96
97
    /**
98
     * Build::optionMain
99
     *
100
     * @param string $name
101
     */
102
    public function optionMain($main)
103
    {
104
        $this->optionMain = $main;
105
    }
106
107
    // ------------------------------------------------------------------------
108
109
    /**
110
     * Build::execute
111
     *
112
     * @throws \ReflectionException
113
     */
114
    public function execute()
115
    {
116
        parent::execute();
117
118
        $filename = empty($this->optionFilename) ? 'app.phar' : $this->optionFilename;
119
        $filePath = PATH_ROOT . 'build' . DIRECTORY_SEPARATOR . $filename;
0 ignored issues
show
Bug introduced by
The constant O2System\Framework\Cli\Commanders\PATH_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
120
121
        if(ini_get('phar.readonly') == 1 and $this->optionForce === false) {
0 ignored issues
show
Bug Best Practice introduced by
The property optionForce does not exist on O2System\Framework\Cli\Commanders\Build. Since you implemented __get, consider adding a @property annotation.
Loading history...
122
            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

122
            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...
123
                (new Format())
124
                    ->setContextualClass(Format::DANGER)
125
                    ->setString(language()->getLine('CLI_BUILD_PHAR_READONLY'))
126
                    ->setNewLinesAfter(1)
127
            );
128
            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...
129
        }
130
131
        output()->verbose(
0 ignored issues
show
Bug introduced by
The method verbose() 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

131
        output()->/** @scrutinizer ignore-call */ verbose(

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...
132
            (new Format())
133
                ->setContextualClass(Format::INFO)
134
                ->setString(language()->getLine('CLI_BUILD_START'))
135
                ->setNewLinesAfter(1)
136
        );
137
138
        if ( ! is_writable(dirname($filePath))) {
139
            @mkdir(dirname($filePath), 0777, true);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for mkdir(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

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

139
            /** @scrutinizer ignore-unhandled */ @mkdir(dirname($filePath), 0777, true);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
140
141
            output()->verbose(
142
                (new Format())
143
                    ->setContextualClass(Format::INFO)
144
                    ->setString(language()->getLine('CLI_BUILD_MAKE_DIRECTORY'))
145
                    ->setNewLinesAfter(1)
146
            );
147
        }
148
149
        // Build Clean Up
150
        if (file_exists($filePath)) {
151
            unlink($filePath);
152
            output()->verbose(
153
                (new Format())
154
                    ->setContextualClass(Format::WARNING)
155
                    ->setString(language()->getLine('CLI_BUILD_DELETE_OLD_BUILD'))
156
                    ->setNewLinesAfter(1)
157
            );
158
        }
159
160
        if (file_exists($filePath . '.gz')) {
161
            unlink($filePath . '.gz');
162
            output()->verbose(
163
                (new Format())
164
                    ->setContextualClass(Format::WARNING)
165
                    ->setString(language()->getLine('CLI_BUILD_DELETE_OLD_BUILD_COMPRESSION'))
166
                    ->setNewLinesAfter(1)
167
            );
168
        }
169
170
        $phar = new \Phar($filePath, 0, $filename);
171
172
        // Build from PATH_ROOT using Recursive Directory Iterator
173
        $phar->buildFromIterator(
174
            new \RecursiveIteratorIterator(
175
                new \RecursiveDirectoryIterator(PATH_ROOT, \FilesystemIterator::SKIP_DOTS)),
176
            PATH_ROOT);
177
178
        // Define main script
179
        $main = 'public/index.php';
180
        if (empty($this->optionMain)) {
181
            // Default Carbon Boilerplate Detection
182
            if (is_file(PATH_APP . 'console')) {
183
                $main = 'app/console';
184
185
                output()->verbose(
186
                    (new Format())
187
                        ->setContextualClass(Format::WARNING)
188
                        ->setString(language()->getLine('CLI_BUILD_USE_CARBON_DEFAULT'))
189
                        ->setNewLinesAfter(1)
190
                );
191
            }
192
        } else {
193
            $main = $this->optionMain;
194
        }
195
196
        $phar->setStub($phar->createDefaultStub($main));
197
198
        output()->verbose(
199
            (new Format())
200
                ->setContextualClass(Format::INFO)
201
                ->setString(language()->getLine('CLI_BUILD_START_GZ_COMPRESSION'))
202
                ->setNewLinesAfter(1)
203
        );
204
205
        $phar->compress(\Phar::GZ);
206
207
        output()->write(
208
            (new Format())
209
                ->setContextualClass(Format::SUCCESS)
210
                ->setString(language()->getLine('CLI_BUILD_SUCCESSFUL'))
211
                ->setNewLinesAfter(1)
212
        );
213
    }
214
}