| Conditions | 9 |
| Paths | 17 |
| Total Lines | 54 |
| Code Lines | 36 |
| 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 |
||
| 65 | public function map(array $data): array |
||
| 66 | { |
||
| 67 | $attrs = []; |
||
| 68 | foreach ($this->map as $attr => $value) { |
||
| 69 | if (array_key_exists($value['attr'], $data)) { |
||
| 70 | $this->logger->info('found attribut mapping ['.$attr.'] => [('.$value['type'].') '.$value['attr'].']', [ |
||
| 71 | 'category' => get_class($this), |
||
| 72 | ]); |
||
| 73 | |||
| 74 | if ($value['type'] == 'array') { |
||
| 75 | $store = $data[$value['attr']]; |
||
| 76 | } else { |
||
| 77 | $store = $data[$value['attr']]; |
||
| 78 | if (is_array($store) { |
||
|
|
|||
| 79 | $store = $store[0]; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | switch ($value['type']) { |
||
| 84 | case 'array': |
||
| 85 | $arr = (array)$data[$value['attr']]; |
||
| 86 | unset($arr['count']); |
||
| 87 | $attrs[$attr] = $arr; |
||
| 88 | break; |
||
| 89 | |||
| 90 | case 'string': |
||
| 91 | $attrs[$attr] = (string)$store; |
||
| 92 | break; |
||
| 93 | |||
| 94 | case 'int': |
||
| 95 | $attrs[$attr] = (int)$store; |
||
| 96 | break; |
||
| 97 | |||
| 98 | case 'bool': |
||
| 99 | $attrs[$attr] = (bool)$store; |
||
| 100 | break; |
||
| 101 | |||
| 102 | default: |
||
| 103 | $this->logger->error('unknown attribute type ['.$value['type'].'] for attribute ['.$attr.']; use one of [array,string,int,bool]', [ |
||
| 104 | 'category' => get_class($this), |
||
| 105 | ]); |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $this->logger->warning('auth attribute ['.$value['attr'].'] was not found from authentication adapter response', [ |
||
| 110 | 'category' => get_class($this), |
||
| 111 | ]); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | return $attrs; |
||
| 116 | } |
||
| 117 | } |
||
| 118 |