Conditions | 10 |
Paths | 10 |
Total Lines | 33 |
Code Lines | 19 |
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 |
||
13 | public function map(Request $request, array $propsMap): array |
||
14 | { |
||
15 | if (!array_key_exists('path', $propsMap)) { |
||
16 | return []; |
||
17 | } |
||
18 | |||
19 | $pathProps = (array)$propsMap['path']; |
||
20 | $result = []; |
||
21 | foreach ($pathProps as $propName => $propValue) { |
||
22 | $required = false; |
||
23 | if (strpos($propName, self::REQ_CHAR) === 0) { |
||
24 | $required = true; |
||
25 | $propName = ltrim($propName, self::REQ_CHAR); |
||
26 | } |
||
27 | |||
28 | if ($required && $request->attributes->has($propName) && empty($request->attributes->get($propName))) { |
||
29 | throw ParamMapperException::paramEmpty($propName); |
||
30 | } |
||
31 | |||
32 | if (!$request->attributes->has($propName)) { |
||
33 | if ($required && $request->attributes->get($propName) === null) { |
||
34 | throw ParamMapperException::noParamFound($propName); |
||
35 | } |
||
36 | |||
37 | continue; |
||
38 | } |
||
39 | |||
40 | $finalPropName = $propValue ?? $propName; |
||
41 | $result[$finalPropName] = $request->attributes->get($propName); |
||
42 | } |
||
43 | |||
44 | return $result; |
||
45 | } |
||
46 | } |
||
47 |