Conditions | 13 |
Paths | 41 |
Total Lines | 50 |
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 |
||
103 | public static function getResolved(Resolver $resolver, object $service, \ReflectionClass $reflection): object |
||
104 | { |
||
105 | if (\PHP_VERSION_ID < 80000) { |
||
106 | return $service; |
||
|
|||
107 | } |
||
108 | |||
109 | $properties = []; |
||
110 | |||
111 | foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { |
||
112 | if (empty($propertyAttributes = $property->getAttributes(Inject::class))) { |
||
113 | continue; |
||
114 | } |
||
115 | |||
116 | if (!empty($pValue = $propertyAttributes[0]->getArguments()[0] ?? null)) { |
||
117 | $properties[0][$property->getName()] = $resolver->resolveReference($pValue); |
||
118 | continue; |
||
119 | } |
||
120 | |||
121 | foreach (Resolver::getTypes($property) as $pType) { |
||
122 | if (Reflection::isBuiltinType($pType)) { |
||
123 | continue; |
||
124 | } |
||
125 | |||
126 | if (!empty($pValue = $resolver->resolveReference('?' . $pType))) { |
||
127 | $properties[0][$property->getName()] = $pValue; |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | |||
132 | foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
||
133 | if (empty($methodAttributes = $method->getAttributes(Inject::class))) { |
||
134 | continue; |
||
135 | } |
||
136 | |||
137 | if (!empty($methodAttributes[0]->getArguments())) { |
||
138 | throw new ContainerResolutionException(\sprintf('Method with Inject attributes does not support having arguments.')); |
||
139 | } |
||
140 | |||
141 | $properties[1][$method->getName()] = $resolver->autowireArguments($method); |
||
142 | } |
||
143 | |||
144 | if (!empty($properties)) { |
||
145 | $service = new self($service, $properties); |
||
146 | |||
147 | if (null === $resolver->getBuilder()) { |
||
148 | $service = $service->resolve(); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | return $service; |
||
153 | } |
||
155 |