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