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