| Conditions | 8 | 
| Paths | 546 | 
| Total Lines | 101 | 
| Code Lines | 57 | 
| 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  | 
            ||
| 87 | protected function execute(InputInterface $input, OutputInterface $output): int  | 
            ||
| 88 |     { | 
            ||
| 89 | $io = new SymfonyStyle($input, $output);  | 
            ||
| 90 | |||
| 91 | $pharPath = $input->getArgument(self::PHAR_ARG);  | 
            ||
| 92 | |||
| 93 |         if (null === $pharPath) { | 
            ||
| 94 | $pharPath = $this->guessPharPath($input, $output, $io);  | 
            ||
| 95 | }  | 
            ||
| 96 | |||
| 97 |         if (null === $pharPath) { | 
            ||
| 98 | return 1;  | 
            ||
| 99 | }  | 
            ||
| 100 | |||
| 101 | Assertion::file($pharPath);  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 102 | |||
| 103 | $pharPath = false !== realpath($pharPath) ? realpath($pharPath) : $pharPath;  | 
            ||
| 104 | |||
| 105 | $io->newLine();  | 
            ||
| 106 | $io->writeln(  | 
            ||
| 107 | sprintf(  | 
            ||
| 108 | '🐳 Generating a Dockerfile for the PHAR "<comment>%s</comment>"',  | 
            ||
| 109 | $pharPath  | 
            ||
| 110 | )  | 
            ||
| 111 | );  | 
            ||
| 112 | |||
| 113 | $tmpPharPath = $this->createTemporaryPhar($pharPath);  | 
            ||
| 114 | |||
| 115 | $requirementsPhar = 'phar://'.$tmpPharPath.'/.box/.requirements.php';  | 
            ||
| 116 | |||
| 117 | $dockerFileContents = self::DOCKER_FILE_TEMPLATE;  | 
            ||
| 118 | |||
| 119 |         try { | 
            ||
| 120 |             if (false === file_exists($requirementsPhar)) { | 
            ||
| 121 | $io->error(  | 
            ||
| 122 | 'Cannot retrieve the requirements for the PHAR. Make sure the PHAR has been built with Box and the '  | 
            ||
| 123 | .'requirement checker enabled.'  | 
            ||
| 124 | );  | 
            ||
| 125 | }  | 
            ||
| 126 | |||
| 127 | $requirements = include $requirementsPhar;  | 
            ||
| 128 | |||
| 129 | $dockerFileContents = str_replace(  | 
            ||
| 130 | '__BASE_PHP_IMAGE_TOKEN__',  | 
            ||
| 131 | $this->retrievePhpImageName($requirements),  | 
            ||
| 132 | $dockerFileContents  | 
            ||
| 133 | );  | 
            ||
| 134 | |||
| 135 | $dockerFileContents = str_replace(  | 
            ||
| 136 | '__PHP_EXTENSIONS_TOKEN__',  | 
            ||
| 137 | $this->retrievePhpExtensions($requirements),  | 
            ||
| 138 | $dockerFileContents  | 
            ||
| 139 | );  | 
            ||
| 140 | |||
| 141 | $dockerFileContents = str_replace(  | 
            ||
| 142 | '__PHAR_FILE_PATH_TOKEN__',  | 
            ||
| 143 | make_path_relative($pharPath, getcwd()),  | 
            ||
| 144 | $dockerFileContents  | 
            ||
| 145 | );  | 
            ||
| 146 | |||
| 147 | $dockerFileContents = str_replace(  | 
            ||
| 148 | '__PHAR_FILE_NAME_TOKEN__',  | 
            ||
| 149 | basename($pharPath),  | 
            ||
| 150 | $dockerFileContents  | 
            ||
| 151 | );  | 
            ||
| 152 | |||
| 153 | dump_file(self::DOCKER_FILE_NAME, $dockerFileContents);  | 
            ||
| 154 | |||
| 155 |             if (file_exists(self::DOCKER_FILE_NAME)) { | 
            ||
| 156 | $remove = $io->askQuestion(  | 
            ||
| 157 | new ConfirmationQuestion(  | 
            ||
| 158 | 'A Docker file has already been found, are you sure you want to override it?',  | 
            ||
| 159 | true  | 
            ||
| 160 | )  | 
            ||
| 161 | );  | 
            ||
| 162 | |||
| 163 |                 if (false === $remove) { | 
            ||
| 164 |                     $io->writeln('Skipped the docker file generation.'); | 
            ||
| 165 | |||
| 166 | return 0;  | 
            ||
| 167 | }  | 
            ||
| 168 | }  | 
            ||
| 169 | |||
| 170 |             $io->success('Done'); | 
            ||
| 171 | |||
| 172 | $io->writeln(  | 
            ||
| 173 | [  | 
            ||
| 174 | sprintf(  | 
            ||
| 175 | 'You can now inspect your <comment>%s</comment> file or build your container with:',  | 
            ||
| 176 | self::DOCKER_FILE_NAME  | 
            ||
| 177 | ),  | 
            ||
| 178 | '$ <comment>docker build .</comment>',  | 
            ||
| 179 | ]  | 
            ||
| 180 | );  | 
            ||
| 181 |         } finally { | 
            ||
| 182 |             if ($tmpPharPath !== $pharPath) { | 
            ||
| 183 | remove($tmpPharPath);  | 
            ||
| 184 | }  | 
            ||
| 185 | }  | 
            ||
| 186 | |||
| 187 | return 0;  | 
            ||
| 188 | }  | 
            ||
| 290 |