| Conditions | 10 |
| Paths | 9 |
| Total Lines | 44 |
| Code Lines | 25 |
| 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 declare(strict_types=1); |
||
| 63 | public function createMethodDepends(string $className, string $methodName, array $knownParams = []): array |
||
| 64 | { |
||
| 65 | $result = []; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var ReflectionNamedType $type |
||
| 69 | */ |
||
| 70 | foreach ($this->getMethodParams($className, $methodName) as $name => $type) { |
||
| 71 | if ($type !== null && !VarHelper::isScalar($type->getName())) { |
||
| 72 | $result[$name] = $this->get($type->getName()); |
||
|
|
|||
| 73 | continue; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (!isset($knownParams[$name])) { |
||
| 77 | throw new MissingMethodArgumentException('Missing argument ' . $name . ' for method ' . $methodName); |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($type === null) { |
||
| 81 | $result[$name] = $knownParams[$name]; |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | switch ($type->getName()) { |
||
| 86 | case 'int': |
||
| 87 | $result[$name] = (int)$knownParams[$name]; |
||
| 88 | break; |
||
| 89 | |||
| 90 | case 'float': |
||
| 91 | $result[$name] = (float)$knownParams[$name]; |
||
| 92 | break; |
||
| 93 | |||
| 94 | case 'bool': |
||
| 95 | $result[$name] = (bool)$knownParams[$name]; |
||
| 96 | break; |
||
| 97 | |||
| 98 | case 'string': |
||
| 99 | default: |
||
| 100 | $result[$name] = (string)$knownParams[$name]; |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | |||
| 106 | return $result; |
||
| 107 | } |
||
| 136 |