| Conditions | 8 |
| Paths | 32 |
| Total Lines | 56 |
| Code Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 74 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 75 | { |
||
| 76 | $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; |
||
| 77 | $programName = basename($localFilename); |
||
| 78 | $tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar'; |
||
| 79 | |||
| 80 | // check for permissions in local filesystem before start connection process |
||
| 81 | if (! is_writable($tempDirectory = dirname($tempFilename))) { |
||
| 82 | throw new \Exception( |
||
| 83 | $programName . ' update failed: the "' . $tempDirectory . |
||
| 84 | '" directory used to download the temp file could not be written' |
||
| 85 | ); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (! is_writable($localFilename)) { |
||
| 89 | throw new \Exception( |
||
| 90 | $programName . ' update failed: the "' . $localFilename . '" file could not be written' |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 94 | list( $latest, $downloadUrl ) = $this->getLatestReleaseFromGithub('consolidation/robo'); |
||
| 95 | |||
| 96 | |||
| 97 | if (Robo::VERSION == $latest) { |
||
| 98 | $output->writeln('No update available'); |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | $fs = new sfFilesystem(); |
||
| 103 | |||
| 104 | $output->writeln('Downloading ' . Robo::APPLICATION_NAME . ' ' . $latest); |
||
| 105 | |||
| 106 | $fs->copy($downloadUrl, $tempFilename); |
||
| 107 | |||
| 108 | $output->writeln('Download finished'); |
||
| 109 | |||
| 110 | try { |
||
| 111 | \error_reporting(E_ALL); // supress notices |
||
| 112 | |||
| 113 | @chmod($tempFilename, 0777 & ~umask()); |
||
| 114 | // test the phar validity |
||
| 115 | $phar = new \Phar($tempFilename); |
||
| 116 | // free the variable to unlock the file |
||
| 117 | unset($phar); |
||
| 118 | @rename($tempFilename, $localFilename); |
||
| 119 | $output->writeln('<info>Successfully updated ' . $programName . '</info>'); |
||
| 120 | $this->_exit(); |
||
| 121 | } catch (\Exception $e) { |
||
| 122 | @unlink($tempFilename); |
||
| 123 | if (! $e instanceof \UnexpectedValueException && ! $e instanceof \PharException) { |
||
| 124 | throw $e; |
||
| 125 | } |
||
| 126 | $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>'); |
||
| 127 | $output->writeln('<error>Please re-run the self-update command to try again.</error>'); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 144 |
This check marks private properties in classes that are never used. Those properties can be removed.