| Conditions | 15 |
| Paths | 65 |
| Total Lines | 84 |
| Code Lines | 46 |
| 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 |
||
| 36 | public function getExtensions(): array |
||
| 37 | { |
||
| 38 | $generator = new DummyGenerator($this->definitionContainer); |
||
| 39 | $definitions = $this->getDefinitions(); |
||
| 40 | |||
| 41 | $extensions = []; |
||
| 42 | $errors = []; |
||
| 43 | |||
| 44 | foreach ($definitions as $id => $extension) { |
||
| 45 | if (!$this->definitionContainer->has($id)) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | $extensionClass = $this->definitionContainer->get($id); |
||
| 50 | |||
| 51 | if (!$extensionClass instanceof ExtensionInterface) { |
||
| 52 | continue; |
||
| 53 | } |
||
| 54 | |||
| 55 | $extensions[$id] = []; |
||
| 56 | $refl = new \ReflectionObject($extensionClass); |
||
| 57 | |||
| 58 | foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflmethod) { |
||
| 59 | $methodName = $reflmethod->name; |
||
| 60 | |||
| 61 | if ($reflmethod->isConstructor() || str_starts_with($methodName, 'with')) { |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | $parameters = []; |
||
| 65 | |||
| 66 | foreach ($reflmethod->getParameters() as $reflparameter) { |
||
| 67 | $parameter = []; |
||
| 68 | $parameter['name'] = '$' . $reflparameter->getName(); |
||
| 69 | $parameter['type'] = $this->getTypes($reflparameter->getType()); |
||
| 70 | |||
| 71 | |||
| 72 | if ($reflparameter->isDefaultValueAvailable()) { |
||
| 73 | $parameter['default'] = $reflparameter->getDefaultValue(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $parameters[] = $parameter; |
||
| 77 | } |
||
| 78 | |||
| 79 | $parametersJoined = []; |
||
| 80 | |||
| 81 | foreach ($parameters as $parameter) { |
||
| 82 | if ($this->withDetails && !empty($parameter['type'])) { |
||
| 83 | $parametersString = $parameter['type'] . ' ' . $parameter['name']; |
||
| 84 | } else { |
||
| 85 | $parametersString = $parameter['name']; |
||
| 86 | } |
||
| 87 | |||
| 88 | if (!empty($parameter['default'])) { |
||
| 89 | $parametersString .= ' = ' . $parameter['default']; |
||
| 90 | } |
||
| 91 | |||
| 92 | $parametersJoined[] = $parametersString; |
||
| 93 | } |
||
| 94 | |||
| 95 | $parametersString = implode(', ', $parametersJoined); |
||
| 96 | |||
| 97 | try { |
||
| 98 | $example = $generator->$methodName(); |
||
| 99 | } catch (\Throwable $e) { |
||
| 100 | $errors[$methodName] = $e->getMessage(); |
||
| 101 | $example = ''; |
||
| 102 | } |
||
| 103 | |||
| 104 | $example = $this->formatExample($example); |
||
| 105 | $returnTypes = $this->getTypes($reflmethod->getReturnType()); |
||
| 106 | |||
| 107 | if ($this->withDetails) { |
||
| 108 | $extensions[$id][$methodName . ' (' . $parametersString . ')'] = '(' . $returnTypes . ') ' . $example; |
||
| 109 | } else { |
||
| 110 | $extensions[$id][$methodName . '(' . $parametersString . ')'] = $example; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | // it might be easier to go with this, instead of returning |
||
| 116 | // file_put_contents('docs_result_'.uniqid('', true).'.txt', print_r($extensions, true)); |
||
| 117 | // var_export($errors); |
||
| 118 | |||
| 119 | return $extensions; |
||
| 120 | } |
||
| 169 |