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