| Conditions | 3 |
| Paths | 1 |
| Total Lines | 71 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 50 |
| CRAP Score | 3.0005 |
| 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 |
||
| 87 | 1 | private function linkNodes(Map $nodes): void |
|
| 88 | { |
||
| 89 | $nodes |
||
| 90 | 1 | ->values() |
|
| 91 | 1 | ->filter(static function(array $pair): bool { |
|
| 92 | //do not try to link nodes for services that do not depend on |
||
| 93 | //other services |
||
| 94 | 1 | return $pair[1] |
|
| 95 | 1 | ->arguments() |
|
| 96 | 1 | ->filter(static function(Argument $argument): bool { |
|
| 97 | 1 | return $argument instanceof HoldReference; |
|
| 98 | 1 | }) |
|
| 99 | 1 | ->size() > 0; |
|
| 100 | 1 | }) |
|
| 101 | 1 | ->foreach(static function(array $pair) use ($nodes): void { |
|
| 102 | 1 | $pair[1] |
|
| 103 | 1 | ->arguments() |
|
| 104 | 1 | ->filter(static function(Argument $argument): bool { |
|
| 105 | 1 | return $argument instanceof HoldReference; |
|
| 106 | 1 | }) |
|
| 107 | 1 | ->foreach(static function(HoldReference $argument) use ($pair, $nodes): void { |
|
| 108 | 1 | $name = (string) Element::build($argument->reference())->name(); |
|
| 109 | |||
| 110 | //an argument or a dependency |
||
| 111 | 1 | if (!$nodes->contains($name)) { |
|
| 112 | 1 | $pair[0]->linkedTo(Node::named($name)); |
|
| 113 | |||
| 114 | 1 | return; |
|
| 115 | } |
||
| 116 | |||
| 117 | 1 | $pair[0]->linkedTo( |
|
| 118 | 1 | $nodes->get($name)[0] |
|
| 119 | ); |
||
| 120 | 1 | }); |
|
| 121 | 1 | }); |
|
| 122 | $nodes |
||
| 123 | 1 | ->values() |
|
| 124 | 1 | ->filter(static function(array $pair): bool { |
|
| 125 | //do not try to link nodes for services that do not depend on |
||
| 126 | //other services |
||
| 127 | 1 | return $pair[1] |
|
| 128 | 1 | ->arguments() |
|
| 129 | 1 | ->filter(static function(Argument $argument): bool { |
|
| 130 | 1 | return $argument instanceof HoldReferences; |
|
| 131 | 1 | }) |
|
| 132 | 1 | ->size() > 0; |
|
| 133 | 1 | }) |
|
| 134 | 1 | ->foreach(static function(array $pair) use ($nodes): void { |
|
| 135 | 1 | $pair[1] |
|
| 136 | 1 | ->arguments() |
|
| 137 | 1 | ->filter(static function(Argument $argument): bool { |
|
| 138 | 1 | return $argument instanceof HoldReferences; |
|
| 139 | 1 | }) |
|
| 140 | 1 | ->reduce( |
|
| 141 | 1 | Set::of(Name::class), |
|
| 142 | 1 | static function(Set $names, HoldReferences $argument): Set { |
|
| 143 | 1 | return $names->merge($argument->references()); |
|
|
1 ignored issue
–
show
|
|||
| 144 | 1 | } |
|
| 145 | ) |
||
| 146 | 1 | ->foreach(static function(Name $name) use ($pair, $nodes): void { |
|
| 147 | 1 | $name = (string) Element::build($name)->name(); |
|
| 148 | |||
| 149 | //an argument or a dependency |
||
| 150 | 1 | if (!$nodes->contains($name)) { |
|
| 151 | $pair[0]->linkedTo(Node::named($name)); |
||
| 152 | |||
| 153 | return; |
||
| 154 | } |
||
| 155 | |||
| 156 | 1 | $pair[0]->linkedTo( |
|
| 157 | 1 | $nodes->get($name)[0] |
|
| 158 | ); |
||
| 186 |