| Conditions | 19 |
| Paths | 896 |
| Total Lines | 83 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 89 | public function __construct(array $config, $reserved) |
||
| 90 | { |
||
| 91 | parent::__construct($config, $reserved); |
||
| 92 | |||
| 93 | // Check for the deny option |
||
| 94 | // Must be bool specifically, if not, it might be for an attrib filter below |
||
| 95 | if (isset($config['deny']) && is_bool($config['deny'])) { |
||
| 96 | $this->deny = $config['deny']; |
||
| 97 | unset($config['deny']); |
||
| 98 | } |
||
| 99 | |||
| 100 | // Check for the regex option |
||
| 101 | // Must be bool specifically, if not, it might be for an attrib filter below |
||
| 102 | if (isset($config['regex']) && is_bool($config['regex'])) { |
||
| 103 | $this->regex = $config['regex']; |
||
| 104 | unset($config['regex']); |
||
| 105 | } |
||
| 106 | |||
| 107 | // Check for the reject_msg option; Must be array of languages |
||
| 108 | if (isset($config['reject_msg']) && is_array($config['reject_msg'])) { |
||
| 109 | $this->reject_msg = $config['reject_msg']; |
||
| 110 | unset($config['reject_msg']); |
||
| 111 | } |
||
| 112 | |||
| 113 | // Check for the errorURL option |
||
| 114 | // Must be bool specifically, if not, it might be for an attrib filter below |
||
| 115 | if (isset($config['errorURL']) && is_bool($config['errorURL'])) { |
||
| 116 | $this->errorURL = $config['errorURL']; |
||
| 117 | unset($config['errorURL']); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (isset($config['allow_reauthentication']) && is_bool($config['allow_reauthentication'])) { |
||
| 121 | $this->allow_reauthentication = $config['allow_reauthentication']; |
||
| 122 | unset($config['allow_reauthentication']); |
||
| 123 | } |
||
| 124 | |||
| 125 | if (isset($config['show_user_attribute']) && is_string($config['show_user_attribute'])) { |
||
| 126 | $this->show_user_attribute = $config['show_user_attribute']; |
||
| 127 | unset($config['show_user_attribute']); |
||
| 128 | } |
||
| 129 | |||
| 130 | foreach ($config as $attribute => $values) { |
||
| 131 | if (is_string($values)) { |
||
| 132 | $arrayUtils = new Utils\Arrays(); |
||
| 133 | $values = $arrayUtils->arrayize($values); |
||
| 134 | } elseif (!is_array($values)) { |
||
| 135 | throw new Error\Exception(sprintf( |
||
| 136 | 'Filter Authorize: Attribute values is neither string nor array: %s', |
||
| 137 | var_export($attribute, true), |
||
| 138 | )); |
||
| 139 | } |
||
| 140 | |||
| 141 | // Extract spEntityIDs if present |
||
| 142 | $spEntityIDs = null; |
||
| 143 | if (isset($values['spEntityIDs'])) { |
||
| 144 | Assert::isArray( |
||
| 145 | $values['spEntityIDs'], |
||
| 146 | sprintf( |
||
| 147 | 'Filter Authorize: spEntityIDs must be an array for attribute: %s', |
||
| 148 | var_export($attribute, true), |
||
| 149 | ), |
||
| 150 | Error\Exception::class, |
||
| 151 | ); |
||
| 152 | Assert::allValidEntityID($values['spEntityIDs']); |
||
| 153 | |||
| 154 | $spEntityIDs = $values['spEntityIDs']; |
||
| 155 | unset($values['spEntityIDs']); |
||
| 156 | } |
||
| 157 | |||
| 158 | foreach ($values as $value) { |
||
| 159 | if (!is_string($value)) { |
||
| 160 | throw new Error\Exception(sprintf( |
||
| 161 | 'Filter Authorize: Each value should be a string for attribute: %s value: %s config: %s', |
||
| 162 | var_export($attribute, true), |
||
| 163 | var_export($value, true), |
||
| 164 | var_export($config, true), |
||
| 165 | )); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | $this->valid_attribute_values[$attribute] = [ |
||
| 170 | 'values' => $values, |
||
| 171 | 'spEntityIDs' => $spEntityIDs, |
||
| 172 | ]; |
||
| 279 |