| Conditions | 11 |
| Paths | 58 |
| Total Lines | 58 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 64 | private function askForParameterValues(Command $command, array $predefinedParameters = []): array |
||
| 65 | { |
||
| 66 | $values = []; |
||
| 67 | |||
| 68 | $commandIdentifier = $command->getFullyQualifiedIdentifier(); |
||
| 69 | |||
| 70 | foreach ($command->getParameters() as $identifier => $parameter) { |
||
| 71 | |||
| 72 | if (array_key_exists($identifier, $predefinedParameters)) { |
||
| 73 | $values[] = new ParameterValue($identifier, $predefinedParameters[$identifier], $parameter->getType()); |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | |||
| 77 | $fullParameterIdentifier = $commandIdentifier . ':' . $identifier; |
||
| 78 | |||
| 79 | $additional = $this->getAdditionalInfo($fullParameterIdentifier, $parameter); |
||
| 80 | |||
| 81 | if ($parameter->getName()) { |
||
| 82 | $name = $identifier . ' (' . $parameter->getName() . ')'; |
||
| 83 | } else { |
||
| 84 | $name = $identifier; |
||
| 85 | } |
||
| 86 | |||
| 87 | $valid = false; |
||
| 88 | |||
| 89 | while (!$valid) { |
||
| 90 | if ($parameter->hasValues()) { |
||
| 91 | $value = $this->askForEnum(' Select value for ' . $name . $additional['string'] . ": \n", $parameter->getValues()); |
||
| 92 | } else { |
||
| 93 | $question = new Question(' Select value for ' . $name . $additional['string'] . ": ", $additional['value']); |
||
| 94 | if ($parameter instanceof PasswordParameter) { |
||
| 95 | $question->setHidden(true); |
||
| 96 | $question->setHiddenFallback(false); |
||
| 97 | } |
||
| 98 | $value = $this->questionHelper->ask($this->input, $this->output, $question); |
||
| 99 | } |
||
| 100 | |||
| 101 | $validationResult = $parameter->validate($value); |
||
| 102 | |||
| 103 | $valid = $validationResult->isValid(); |
||
| 104 | |||
| 105 | if (!$valid) { |
||
| 106 | $this->output->writeln(' <error>' . $validationResult->getValidationMessage() . '</error>'); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($value) { |
||
| 111 | $value = $parameter->getPrefix() . $value . $parameter->getSuffix(); |
||
| 112 | } |
||
| 113 | |||
| 114 | $values[] = new ParameterValue($identifier, $value, $parameter->getType()); |
||
| 115 | |||
| 116 | if ($value && !($parameter instanceof PasswordParameter)) { |
||
| 117 | $this->memory->addParameter($fullParameterIdentifier, $value); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $values; |
||
| 122 | } |
||
| 198 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: