| Conditions | 10 |
| Paths | 32 |
| Total Lines | 56 |
| 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 |
||
| 73 | public function map(array $data): array |
||
| 74 | { |
||
| 75 | $attrs = []; |
||
| 76 | foreach ($this->map as $attr => $value) { |
||
| 77 | if (array_key_exists($value['attr'], $data)) { |
||
| 78 | $this->logger->info('found attribute mapping ['.$attr.'] => [('.$value['type'].') '.$value['attr'].']', [ |
||
| 79 | 'category' => get_class($this), |
||
| 80 | ]); |
||
| 81 | |||
| 82 | if ('array' === $value['type']) { |
||
| 83 | $store = $data[$value['attr']]; |
||
| 84 | } else { |
||
| 85 | $store = $data[$value['attr']]; |
||
| 86 | if (is_array($store)) { |
||
| 87 | $store = $store[0]; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if (isset($this->mapper[$value['type']])) { |
||
| 92 | $attrs[$attr] = $this->mapper[$value['type']]->call($this, $store); |
||
| 93 | } |
||
| 94 | |||
| 95 | switch ($value['type']) { |
||
| 96 | case 'array': |
||
| 97 | $arr = (array) $data[$value['attr']]; |
||
| 98 | unset($arr['count']); |
||
| 99 | $attrs[$attr] = $arr; |
||
| 100 | |||
| 101 | break; |
||
| 102 | case 'string': |
||
| 103 | $attrs[$attr] = (string) $store; |
||
| 104 | |||
| 105 | break; |
||
| 106 | case 'int': |
||
| 107 | $attrs[$attr] = (int) $store; |
||
| 108 | |||
| 109 | break; |
||
| 110 | case 'bool': |
||
| 111 | $attrs[$attr] = (bool) $store; |
||
| 112 | |||
| 113 | break; |
||
| 114 | default: |
||
| 115 | $this->logger->error('unknown attribute type ['.$value['type'].'] for attribute ['.$attr.']; use one of [array,string,int,bool]', [ |
||
| 116 | 'category' => get_class($this), |
||
| 117 | ]); |
||
| 118 | |||
| 119 | break; |
||
| 120 | } |
||
| 121 | } else { |
||
| 122 | $this->logger->warning('auth attribute ['.$value['attr'].'] was not found from authentication adapter response', [ |
||
| 123 | 'category' => get_class($this), |
||
| 124 | ]); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | return $attrs; |
||
| 129 | } |
||
| 131 |