| Conditions | 8 |
| Paths | 274 |
| Total Lines | 84 |
| Code Lines | 45 |
| 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 |
||
| 62 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 63 | { |
||
| 64 | $io = new SymfonyStyle($input, $output); |
||
| 65 | |||
| 66 | $pharPath = $input->getArgument(self::PHAR_ARG); |
||
| 67 | |||
| 68 | if (null === $pharPath) { |
||
| 69 | $pharPath = $this->guessPharPath($input, $output, $io); |
||
| 70 | } |
||
| 71 | |||
| 72 | if (null === $pharPath) { |
||
| 73 | return 1; |
||
| 74 | } |
||
| 75 | |||
| 76 | Assertion::file($pharPath); |
||
|
|
|||
| 77 | |||
| 78 | $pharPath = false !== realpath($pharPath) ? realpath($pharPath) : $pharPath; |
||
| 79 | |||
| 80 | $io->newLine(); |
||
| 81 | $io->writeln( |
||
| 82 | sprintf( |
||
| 83 | '🐳 Generating a Dockerfile for the PHAR "<comment>%s</comment>"', |
||
| 84 | $pharPath |
||
| 85 | ) |
||
| 86 | ); |
||
| 87 | |||
| 88 | $tmpPharPath = $this->createTemporaryPhar($pharPath); |
||
| 89 | |||
| 90 | $requirementsPhar = 'phar://'.$tmpPharPath.'/.box/.requirements.php'; |
||
| 91 | |||
| 92 | try { |
||
| 93 | if (false === file_exists($requirementsPhar)) { |
||
| 94 | $io->error( |
||
| 95 | 'Cannot retrieve the requirements for the PHAR. Make sure the PHAR has been built with Box and the ' |
||
| 96 | .'requirement checker enabled.' |
||
| 97 | ); |
||
| 98 | |||
| 99 | return 1; |
||
| 100 | } |
||
| 101 | |||
| 102 | $requirements = include $requirementsPhar; |
||
| 103 | |||
| 104 | $dockerFileContents = DockerFileGenerator::createForRequirements( |
||
| 105 | $requirements, |
||
| 106 | make_path_relative($pharPath, getcwd()) |
||
| 107 | ) |
||
| 108 | ->generate() |
||
| 109 | ; |
||
| 110 | |||
| 111 | if (file_exists(self::DOCKER_FILE_NAME)) { |
||
| 112 | $remove = $io->askQuestion( |
||
| 113 | new ConfirmationQuestion( |
||
| 114 | 'A Docker file has already been found, are you sure you want to override it?', |
||
| 115 | true |
||
| 116 | ) |
||
| 117 | ); |
||
| 118 | |||
| 119 | if (false === $remove) { |
||
| 120 | $io->writeln('Skipped the docker file generation.'); |
||
| 121 | |||
| 122 | return 0; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | dump_file(self::DOCKER_FILE_NAME, $dockerFileContents); |
||
| 127 | |||
| 128 | $io->success('Done'); |
||
| 129 | |||
| 130 | $io->writeln( |
||
| 131 | [ |
||
| 132 | sprintf( |
||
| 133 | 'You can now inspect your <comment>%s</comment> file or build your container with:', |
||
| 134 | self::DOCKER_FILE_NAME |
||
| 135 | ), |
||
| 136 | '$ <comment>docker build .</comment>', |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | } finally { |
||
| 140 | if ($tmpPharPath !== $pharPath) { |
||
| 141 | remove($tmpPharPath); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | return 0; |
||
| 146 | } |
||
| 192 |