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