Conditions | 9 |
Paths | 50 |
Total Lines | 98 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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; |
||
|
|||
120 | |||
121 | if(ini_get('phar.readonly') == 1 and $this->optionForce === false) { |
||
122 | output()->write( |
||
123 | (new Format()) |
||
124 | ->setContextualClass(Format::DANGER) |
||
125 | ->setString(language()->getLine('CLI_BUILD_PHAR_READONLY')) |
||
126 | ->setNewLinesAfter(1) |
||
127 | ); |
||
128 | exit(EXIT_ERROR); |
||
129 | } |
||
130 | |||
131 | output()->verbose( |
||
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); |
||
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 | ); |
||
214 | } |