| Conditions | 8 |
| Paths | 13 |
| Total Lines | 53 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 61 | protected function execute(InputInterface $in, OutputInterface $out) |
||
| 62 | { |
||
| 63 | if (Phar::running() === '') { |
||
| 64 | $out->writeln('<error>This command can only be used to upgrade the phar. Use composer if you run pvra from source</error>'); |
||
| 65 | return 2; |
||
| 66 | } |
||
| 67 | $out->writeln('Checking version for updates...'); |
||
| 68 | $out->writeln('Attempting to connect to repository: ' . $this->slug); |
||
| 69 | list($ghReleases, $header) = $this->getReleases(); |
||
| 70 | if ($in->getOption('verbose')) { |
||
| 71 | $headers = $this->parseHeader($header); |
||
| 72 | $out->writeln('Github api limit: ' . $headers['X-RateLimit-Limit']); |
||
| 73 | $out->writeln('Github api limit remaining: ' . $headers['X-RateLimit-Remaining']); |
||
| 74 | } |
||
| 75 | $ghReleasesContent = json_decode($ghReleases, true); |
||
| 76 | unset($ghReleases); |
||
| 77 | if (!empty($ghReleasesContent)) { |
||
| 78 | $remoteVersion = substr($ghReleasesContent[0]['tag_name'], 1); |
||
| 79 | $out->writeln('Your version: ' . $this->getApplication()->getVersion() |
||
| 80 | . '(' . $this->getComparableVersion() . ')'); |
||
| 81 | $out->writeln('Current remote version is: ' . $remoteVersion); |
||
| 82 | $compared = version_compare($this->getComparableVersion(), $remoteVersion); |
||
| 83 | if ($compared < 0) { |
||
| 84 | $out->writeln('A newer version is available.'); |
||
| 85 | $question = new ConfirmationQuestion('Do you wish to upgrade to ' . $remoteVersion . ' ? [y/N]: '); |
||
| 86 | if ($this->getHelper('question')->ask($in, $out, $question)) { |
||
| 87 | $out->writeln('Upgrading...'); |
||
| 88 | $temp = tmpfile(); |
||
| 89 | stream_copy_to_stream(fopen($this->getPharUrlFromAssetArray($ghReleasesContent[0]['assets']), 'rb'), |
||
| 90 | $temp); |
||
| 91 | rewind($temp); |
||
| 92 | $running = Phar::running(false); |
||
| 93 | if (!is_writable($running)) { |
||
| 94 | throw new \RuntimeException('The current process needs to be able to delete ' . $running); |
||
| 95 | } |
||
| 96 | unlink($running); |
||
| 97 | $target = fopen($running, 'w+'); |
||
| 98 | stream_copy_to_stream($temp, $target); |
||
| 99 | fclose($target); |
||
| 100 | fclose($temp); |
||
| 101 | $out->writeln($running . ' has been successfully updated.'); |
||
| 102 | } |
||
| 103 | return 0; |
||
| 104 | } elseif ($compared > 0) { |
||
| 105 | $out->writeln('The local version is ahead of the remote version'); |
||
| 106 | return 0; |
||
| 107 | } |
||
| 108 | $out->writeln('Remote and local version are equal'); |
||
| 109 | return 0; |
||
| 110 | } |
||
| 111 | $out->writeln('No releases were found. The phar can\'t be updated automatically.'); |
||
| 112 | return 0; |
||
| 113 | } |
||
| 114 | |||
| 180 |