| Conditions | 6 |
| Paths | 33 |
| Total Lines | 62 |
| Code Lines | 34 |
| 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 |
||
| 63 | protected function executeCommand(IO $io): int |
||
| 64 | { |
||
| 65 | $input = $io->getInput(); |
||
| 66 | |||
| 67 | $file = realpath($input->getArgument(self::PHAR_ARG)); |
||
|
|
|||
| 68 | |||
| 69 | if (false === $file) { |
||
| 70 | $io->error( |
||
| 71 | sprintf( |
||
| 72 | 'The file "%s" could not be found.', |
||
| 73 | $input->getArgument(self::PHAR_ARG) |
||
| 74 | ) |
||
| 75 | ); |
||
| 76 | |||
| 77 | return 1; |
||
| 78 | } |
||
| 79 | |||
| 80 | $tmpFile = create_temporary_phar($file); |
||
| 81 | |||
| 82 | try { |
||
| 83 | $box = Box::create($tmpFile); |
||
| 84 | } catch (Throwable $throwable) { |
||
| 85 | if ($io->isDebug()) { |
||
| 86 | throw new ConsoleRuntimeException( |
||
| 87 | 'The given file is not a valid PHAR', |
||
| 88 | 0, |
||
| 89 | $throwable |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | |||
| 93 | $io->error('The given file is not a valid PHAR'); |
||
| 94 | |||
| 95 | return 1; |
||
| 96 | } |
||
| 97 | |||
| 98 | $restoreLimit = bump_open_file_descriptor_limit($box, $io); |
||
| 99 | |||
| 100 | $outputDir = $input->getArgument(self::OUTPUT_ARG); |
||
| 101 | |||
| 102 | try { |
||
| 103 | remove($outputDir); |
||
| 104 | |||
| 105 | foreach ($box->getPhar() as $pharFile) { |
||
| 106 | /* @var PharFileInfo $pharFile */ |
||
| 107 | dump_file( |
||
| 108 | $outputDir.'/'.$pharFile->getFilename(), |
||
| 109 | (string) $pharFile->getContent() |
||
| 110 | ); |
||
| 111 | } |
||
| 112 | } catch (RuntimeException $exception) { |
||
| 113 | $io->error($exception->getMessage()); |
||
| 114 | |||
| 115 | return 1; |
||
| 116 | } finally { |
||
| 117 | $restoreLimit(); |
||
| 118 | |||
| 119 | remove($tmpFile); |
||
| 120 | } |
||
| 121 | |||
| 122 | $io->success(''); |
||
| 123 | |||
| 124 | return 0; |
||
| 125 | } |
||
| 127 |