Conditions | 10 |
Paths | 80 |
Total Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 $input, OutputInterface $output) |
||
62 | { |
||
63 | $isDryRun = $input->getOption('dry-run'); |
||
64 | $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0]; |
||
65 | $tempFilename = dirname($localFilename) . '/' . basename($localFilename, '.phar') . '-temp.phar'; |
||
66 | |||
67 | // check for permissions in local filesystem before start connection process |
||
68 | if (!is_writable($tempDirectory = dirname($tempFilename))) { |
||
69 | throw new FilesystemException( |
||
70 | 'n98-magerun update failed: the "' . $tempDirectory . |
||
71 | '" directory used to download the temp file could not be written' |
||
72 | ); |
||
73 | } |
||
74 | |||
75 | if (!is_writable($localFilename)) { |
||
76 | throw new FilesystemException( |
||
77 | 'n98-magerun update failed: the "' . $localFilename . '" file could not be written' |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | $io = new ConsoleIO($input, $output, $this->getHelperSet()); |
||
|
|||
82 | $rfs = new RemoteFilesystem($io); |
||
83 | |||
84 | $loadUnstable = $input->getOption('unstable'); |
||
85 | if ($loadUnstable) { |
||
86 | $versionTxtUrl = self::VERSION_TXT_URL_UNSTABLE; |
||
87 | $remoteFilename = self::MAGERUN_DOWNLOAD_URL_UNSTABLE; |
||
88 | } else { |
||
89 | $versionTxtUrl = self::VERSION_TXT_URL_STABLE; |
||
90 | $remoteFilename = self::MAGERUN_DOWNLOAD_URL_STABLE; |
||
91 | } |
||
92 | |||
93 | $latest = trim($rfs->getContents('raw.githubusercontent.com', $versionTxtUrl, false)); |
||
94 | |||
95 | if ($this->isOutdatedVersion($latest, $loadUnstable)) { |
||
96 | $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest)); |
||
97 | |||
98 | try { |
||
99 | if (!$isDryRun) { |
||
100 | $this->downloadNewVersion($output, $rfs, $remoteFilename, $tempFilename); |
||
101 | $this->checkNewPharFile($tempFilename, $localFilename); |
||
102 | } |
||
103 | |||
104 | $output->writeln('<info>Successfully updated n98-magerun</info>'); |
||
105 | $this->showChangelog($output, $loadUnstable, $rfs); |
||
106 | |||
107 | $this->_exit(0); |
||
108 | } catch (\Exception $e) { |
||
109 | @unlink($tempFilename); |
||
110 | if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) { |
||
111 | throw $e; |
||
112 | } |
||
113 | $output->writeln('<error>The download is corrupted (' . $e->getMessage() . ').</error>'); |
||
114 | $output->writeln('<error>Please re-run the self-update command to try again.</error>'); |
||
115 | } |
||
116 | } else { |
||
117 | $output->writeln("<info>You are using the latest n98-magerun version.</info>"); |
||
118 | } |
||
119 | } |
||
120 | |||
213 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: