| Conditions | 18 |
| Paths | 23 |
| Total Lines | 62 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 127 | public function process(array &$state): void |
||
| 128 | { |
||
| 129 | if (!array_key_exists('EntityAttributes', $state['Destination'])) { |
||
| 130 | if ($this->strict === true) { |
||
| 131 | // We do not allow to release any attribute to entity having no entity attribute |
||
| 132 | $state['Destination']['attributes'] = []; |
||
| 133 | } |
||
| 134 | return; |
||
| 135 | } |
||
| 136 | |||
| 137 | if (!array_key_exists('http://macedir.org/entity-category', $state['Destination']['EntityAttributes'])) { |
||
| 138 | if ($this->strict === true) { |
||
| 139 | // We do not allow to release any attribute to entity having no entity category |
||
| 140 | $state['Destination']['attributes'] = []; |
||
| 141 | } |
||
| 142 | return; |
||
| 143 | } |
||
| 144 | $categories = $state['Destination']['EntityAttributes']['http://macedir.org/entity-category']; |
||
| 145 | |||
| 146 | if (!array_key_exists('attributes', $state['Destination'])) { |
||
| 147 | if ($this->default === true) { |
||
| 148 | // handle the case of service providers requesting no attributes and the filter being the default policy |
||
| 149 | $state['Destination']['attributes'] = []; |
||
| 150 | foreach ($categories as $category) { |
||
| 151 | if (!array_key_exists($category, $this->categories)) { |
||
| 152 | continue; |
||
| 153 | } |
||
| 154 | |||
| 155 | $state['Destination']['attributes'] = array_merge( |
||
| 156 | $state['Destination']['attributes'], |
||
| 157 | $this->categories[$category], |
||
| 158 | ); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | return; |
||
| 162 | } |
||
| 163 | |||
| 164 | // iterate over the requested attributes and see if any of the categories allows them |
||
| 165 | foreach ($state['Destination']['attributes'] as $index => $value) { |
||
| 166 | $attrname = $value; |
||
| 167 | if (!is_numeric($index)) { |
||
| 168 | $attrname = $index; |
||
| 169 | } |
||
| 170 | |||
| 171 | $found = false; |
||
| 172 | foreach ($categories as $category) { |
||
| 173 | if (!array_key_exists($category, $this->categories)) { |
||
| 174 | continue; |
||
| 175 | } |
||
| 176 | |||
| 177 | if ( |
||
| 178 | in_array($attrname, $this->categories[$category], true) |
||
| 179 | || $this->allowRequestedAttributes === true |
||
| 180 | ) { |
||
| 181 | $found = true; |
||
| 182 | break; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | if ($found === false && ($this->allowRequestedAttributes === false || $this->strict === true)) { |
||
| 187 | // no category (if any) allows the attribute, so remove it |
||
| 188 | unset($state['Destination']['attributes'][$index]); |
||
| 189 | } |
||
| 193 |