| Conditions | 16 |
| Paths | 164 |
| Total Lines | 114 |
| Code Lines | 75 |
| 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 | $this->__callOptions(); |
||
|
|
|||
| 117 | |||
| 118 | $filename = empty($this->optionFilename) ? 'app.phar' : $this->optionFilename; |
||
| 119 | $filename = str_replace('.phar', '', $filename); |
||
| 120 | $filePath = PATH_ROOT . 'build' . DIRECTORY_SEPARATOR . $filename; |
||
| 121 | |||
| 122 | if (ini_get('phar.readonly') == 1 and $this->optionForce === false) { |
||
| 123 | output()->write( |
||
| 124 | (new Format()) |
||
| 125 | ->setContextualClass(Format::DANGER) |
||
| 126 | ->setString(language()->getLine('CLI_BUILD_PHAR_READONLY')) |
||
| 127 | ->setNewLinesAfter(1) |
||
| 128 | ); |
||
| 129 | exit(EXIT_ERROR); |
||
| 130 | } |
||
| 131 | |||
| 132 | output()->verbose( |
||
| 133 | (new Format()) |
||
| 134 | ->setContextualClass(Format::INFO) |
||
| 135 | ->setString(language()->getLine('CLI_BUILD_START')) |
||
| 136 | ->setNewLinesAfter(1) |
||
| 137 | ); |
||
| 138 | |||
| 139 | // Remove build directory |
||
| 140 | $fileDirectory = dirname($filePath) . DIRECTORY_SEPARATOR; |
||
| 141 | if (is_dir($fileDirectory)) { |
||
| 142 | $directoryHandle = opendir($fileDirectory); |
||
| 143 | if ( ! $directoryHandle) { |
||
| 144 | return false; |
||
| 145 | } |
||
| 146 | while ($file = readdir($directoryHandle)) { |
||
| 147 | if ($file != '.' && $file != '..') { |
||
| 148 | if (is_file($fileDirectory . $file)) { |
||
| 149 | unlink($fileDirectory . $file); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | } |
||
| 153 | closedir($directoryHandle); |
||
| 154 | rmdir($fileDirectory); |
||
| 155 | } |
||
| 156 | |||
| 157 | if ( ! is_writable(dirname($filePath))) { |
||
| 158 | @mkdir(dirname($filePath), 0777, true); |
||
| 159 | |||
| 160 | output()->verbose( |
||
| 161 | (new Format()) |
||
| 162 | ->setContextualClass(Format::INFO) |
||
| 163 | ->setString(language()->getLine('CLI_BUILD_MAKE_DIRECTORY')) |
||
| 164 | ->setNewLinesAfter(1) |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | |||
| 168 | try { |
||
| 169 | $pharData = new \PharData($filePath . '.tar'); |
||
| 170 | $phar = $pharData->convertToExecutable(\Phar::PHAR); |
||
| 171 | |||
| 172 | // Build from PATH_ROOT using Recursive Directory Iterator |
||
| 173 | $phar->buildFromIterator(new \RecursiveIteratorIterator(new \RecursiveCallbackFilterIterator( |
||
| 174 | new \RecursiveDirectoryIterator(PATH_ROOT, |
||
| 175 | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS), |
||
| 176 | function ($current, $key, $iterator) { |
||
| 177 | if ($current->isDir()) { |
||
| 178 | // exclude build directory |
||
| 179 | if ($current->getFilename() === 'build') { |
||
| 180 | return false; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | return true; |
||
| 185 | })), PATH_ROOT); |
||
| 186 | |||
| 187 | // Define main script |
||
| 188 | $main = 'public/index.php'; |
||
| 189 | if (empty($this->optionMain)) { |
||
| 190 | // Default Carbon Boilerplate Detection |
||
| 191 | if (is_file(PATH_APP . 'console')) { |
||
| 192 | $main = 'app/console'; |
||
| 193 | |||
| 194 | output()->verbose( |
||
| 195 | (new Format()) |
||
| 196 | ->setContextualClass(Format::WARNING) |
||
| 197 | ->setString(language()->getLine('CLI_BUILD_USE_CARBON_DEFAULT')) |
||
| 198 | ->setNewLinesAfter(1) |
||
| 199 | ); |
||
| 200 | } |
||
| 201 | } else { |
||
| 202 | $main = $this->optionMain; |
||
| 203 | } |
||
| 204 | |||
| 205 | $phar->setStub($phar->createDefaultStub($main)); |
||
| 206 | |||
| 207 | output()->verbose( |
||
| 208 | (new Format()) |
||
| 209 | ->setContextualClass(Format::INFO) |
||
| 210 | ->setString(language()->getLine('CLI_BUILD_START_GZ_COMPRESSION')) |
||
| 211 | ->setNewLinesAfter(1) |
||
| 212 | ); |
||
| 213 | |||
| 214 | $pharData->convertToExecutable(\Phar::TAR, \Phar::GZ, '.phar.tgz'); |
||
| 215 | |||
| 216 | output()->write( |
||
| 217 | (new Format()) |
||
| 218 | ->setContextualClass(Format::SUCCESS) |
||
| 219 | ->setString(language()->getLine('CLI_BUILD_SUCCESSFUL')) |
||
| 220 | ->setNewLinesAfter(1) |
||
| 221 | ); |
||
| 222 | } catch (\Exception $exception) { |
||
| 223 | output()->write( |
||
| 224 | (new Format()) |
||
| 225 | ->setContextualClass(Format::DANGER) |
||
| 226 | ->setString($exception->getMessage()) |
||
| 227 | ->setNewLinesAfter(1) |
||
| 228 | ); |
||
| 231 | } |
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.