| Conditions | 7 |
| Paths | 6 |
| Total Lines | 62 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 32 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 33 | { |
||
| 34 | $alias = $input->getArgument("alias"); |
||
| 35 | $package = $input->getArgument("package"); |
||
| 36 | |||
| 37 | if (!$this->helper->validateAlias($alias)) { |
||
| 38 | throw CrapException::create( |
||
| 39 | "The alias `%s` is invalid, it should be lowercase, and match: [a-z0-9_.-]+", |
||
| 40 | $alias |
||
| 41 | ); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!$this->helper->validatePackage($package)) { |
||
| 45 | throw CrapException::create( |
||
| 46 | "The package `%s` is invalid, it should match: [a-z0-9_.-]+/[a-z0-9_.-]+", |
||
| 47 | $input->getArgument("package") |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | $override = false; |
||
| 52 | |||
| 53 | if ($this->helper->hasAlias($alias)) { |
||
| 54 | $current = $this->helper->getAlias($alias); |
||
| 55 | |||
| 56 | if ($current == $package) { |
||
| 57 | $output->writeln(sprintf( |
||
| 58 | "<comment>Alias `%s` to package `%s` already exists, silly.</comment>", |
||
| 59 | $alias, |
||
| 60 | $package |
||
| 61 | )); |
||
| 62 | return 0; |
||
| 63 | } |
||
| 64 | |||
| 65 | $helper = $this->getHelper("question"); |
||
| 66 | |||
| 67 | $output->writeln(sprintf( |
||
| 68 | "<comment>Alias `%s` exists and is set to `%s`.</comment>", |
||
| 69 | $alias, |
||
| 70 | $current |
||
| 71 | )); |
||
| 72 | |||
| 73 | $ask = sprintf("Override alias `%s` with `%s`? (y/n) ", $alias, $package); |
||
| 74 | $question = new ConfirmationQuestion($ask, false); |
||
| 75 | |||
| 76 | if (!$helper->ask($input, $output, $question)) { |
||
| 77 | return 0; |
||
| 78 | } |
||
| 79 | |||
| 80 | $override = true; |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->helper->setAlias($alias, $package); |
||
| 84 | |||
| 85 | $output->writeln(sprintf( |
||
| 86 | "<success>Alias `%s` to package `%s` successfully %s.</success>", |
||
| 87 | $alias, |
||
| 88 | $package, |
||
| 89 | $override ? "updated" : "added" |
||
| 90 | )); |
||
| 91 | |||
| 92 | return 0; |
||
| 93 | } |
||
| 94 | |||
| 142 |