| Conditions | 5 |
| Paths | 88 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 83 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 84 | { |
||
| 85 | $io = new SymfonyStyle($input, $output); |
||
| 86 | |||
| 87 | $pharPath = $input->getArgument(self::PHAR_ARG); |
||
| 88 | |||
| 89 | Assertion::file($pharPath); |
||
| 90 | |||
| 91 | $pharPath = false !== realpath($pharPath) ? realpath($pharPath) : $pharPath; |
||
| 92 | |||
| 93 | $io->writeln( |
||
| 94 | sprintf( |
||
| 95 | 'Generating a Dockerfile for the PHAR "<comment>%s</comment>"...', |
||
| 96 | $pharPath |
||
| 97 | ), |
||
| 98 | self::VERBOSITY_LEVEL |
||
| 99 | ); |
||
| 100 | |||
| 101 | $tmpPharPath = $this->createTemporaryPhar($pharPath); |
||
| 102 | |||
| 103 | $requirementsPhar = 'phar://'.$tmpPharPath.'/.box/.requirements.php'; |
||
| 104 | |||
| 105 | $dockerFileContents = self::DOCKER_FILE_TEMPLATE; |
||
| 106 | |||
| 107 | try { |
||
| 108 | if (false === file_exists($requirementsPhar)) { |
||
| 109 | $io->error( |
||
| 110 | 'Cannot retrieve the requirements for the PHAR. Make sure the PHAR has been built with Box and the ' |
||
| 111 | .'requirement checker enabled.' |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 115 | $requirements = include $requirementsPhar; |
||
| 116 | |||
| 117 | $dockerFileContents = str_replace( |
||
| 118 | '__BASE_PHP_IMAGE_TOKEN__', |
||
| 119 | $this->retrievePhpImageName($requirements), |
||
| 120 | $dockerFileContents |
||
| 121 | ); |
||
| 122 | |||
| 123 | $dockerFileContents = str_replace( |
||
| 124 | '__PHP_EXTENSIONS_TOKEN__', |
||
| 125 | $this->retrievePhpExtensions($requirements), |
||
| 126 | $dockerFileContents |
||
| 127 | ); |
||
| 128 | |||
| 129 | $dockerFileContents = str_replace( |
||
| 130 | '__PHAR_FILE_PATH_TOKEN__', |
||
| 131 | make_path_relative($pharPath, getcwd()), |
||
| 132 | $dockerFileContents |
||
| 133 | ); |
||
| 134 | |||
| 135 | $dockerFileContents = str_replace( |
||
| 136 | '__PHAR_FILE_NAME_TOKEN__', |
||
| 137 | basename($pharPath), |
||
| 138 | $dockerFileContents |
||
| 139 | ); |
||
| 140 | |||
| 141 | dump_file('Dockerfile', $dockerFileContents); |
||
| 142 | |||
| 143 | if ($io->getVerbosity() >= self::VERBOSITY_LEVEL) { |
||
| 144 | $io->success('Done'); |
||
| 145 | } |
||
| 146 | } finally { |
||
| 147 | if ($tmpPharPath !== $pharPath) { |
||
| 148 | remove($tmpPharPath); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | return 0; |
||
| 153 | } |
||
| 211 |