| Conditions | 26 |
| Paths | 1137 |
| Total Lines | 110 |
| Code Lines | 74 |
| 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 |
||
| 186 | public function __construct(array $config, $reserved) |
||
| 187 | { |
||
| 188 | parent::__construct($config, $reserved); |
||
| 189 | |||
| 190 | if (array_key_exists('federation', $config)) { |
||
| 191 | if (is_string($config['federation'])) { |
||
| 192 | $this->federation = $config['federation']; |
||
| 193 | } else { |
||
| 194 | throw new \Exception('Federation identifier must be a string'); |
||
| 195 | } |
||
| 196 | } else { |
||
| 197 | throw new \Exception('Federation identifier must be set'); |
||
| 198 | } |
||
| 199 | |||
| 200 | if (array_key_exists('salt', $config)) { |
||
| 201 | if (is_string($config['salt'])) { |
||
| 202 | $this->salt = $config['salt']; |
||
| 203 | } else { |
||
| 204 | throw new \Exception('Salt must be a string'); |
||
| 205 | } |
||
| 206 | } else { |
||
| 207 | $configUtils = new Utils\Config(); |
||
| 208 | $this->salt = $configUtils->getSecretSalt(); |
||
| 209 | } |
||
| 210 | |||
| 211 | if (array_key_exists('userId', $config)) { |
||
| 212 | if (is_string($config['userId'])) { |
||
| 213 | $this->userId = $config['userId']; |
||
| 214 | } else { |
||
| 215 | throw new \Exception('UserId must be a string'); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | if (array_key_exists('realm', $config)) { |
||
| 220 | if (is_string($config['realm'])) { |
||
| 221 | $this->realm = $config['realm']; |
||
| 222 | } else { |
||
| 223 | throw new \Exception('realm must be a string'); |
||
| 224 | } |
||
| 225 | } |
||
| 226 | |||
| 227 | if (array_key_exists('algorithm', $config)) { |
||
| 228 | if ( |
||
| 229 | is_string($config['algorithm']) |
||
| 230 | && in_array($config['algorithm'], hash_algos()) |
||
| 231 | ) { |
||
| 232 | $this->algorithm = $config['algorithm']; |
||
| 233 | } else { |
||
| 234 | throw new \Exception('algorithm must be a hash algorithm listed in hash_algos()'); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | |||
| 238 | if (array_key_exists('exclude', $config)) { |
||
| 239 | if (is_array($config['exclude'])) { |
||
| 240 | $this->exclude = $config['exclude']; |
||
| 241 | } elseif (is_string($config['exclude'])) { |
||
| 242 | $this->exclude = [$config['exclude']]; |
||
| 243 | } else { |
||
| 244 | throw new \Exception('F-ticks exclude must be an array'); |
||
| 245 | } |
||
| 246 | } |
||
| 247 | |||
| 248 | if (array_key_exists('logdest', $config)) { |
||
| 249 | if ( |
||
| 250 | is_string($config['logdest']) && |
||
| 251 | in_array($config['logdest'], ['local', 'syslog', 'remote', 'stdout', 'errorlog', 'simplesamlphp']) |
||
| 252 | ) { |
||
| 253 | $this->logdest = $config['logdest']; |
||
| 254 | } else { |
||
| 255 | throw new \Exception( |
||
| 256 | 'F-ticks log destination must be one of [local, remote, stdout, errorlog, simplesamlphp]' |
||
| 257 | ); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | |||
| 261 | /* match SSP config or we risk mucking up the openlog call */ |
||
| 262 | $globalConfig = Configuration::getInstance(); |
||
| 263 | $defaultFacility = $globalConfig->getInteger( |
||
| 264 | 'logging.facility', |
||
| 265 | defined('LOG_LOCAL5') ? constant('LOG_LOCAL5') : LOG_USER |
||
| 266 | ); |
||
| 267 | $defaultProcessName = $globalConfig->getString('logging.processname', 'SimpleSAMLphp'); |
||
| 268 | if (array_key_exists('logconfig', $config)) { |
||
| 269 | if (is_array($config['logconfig'])) { |
||
| 270 | $this->logconfig = $config['logconfig']; |
||
| 271 | } else { |
||
| 272 | throw new \Exception('F-ticks logconfig must be an array'); |
||
| 273 | } |
||
| 274 | } else { |
||
| 275 | $this->logconfig['facility'] = $defaultFacility; |
||
| 276 | $this->logconfig['processname'] = $defaultProcessName; |
||
| 277 | } |
||
| 278 | /* warn if we risk mucking up the openlog call (doesn't matter for remote syslog) */ |
||
| 279 | if (in_array($this->logdest, ['local', 'syslog'])) { |
||
| 280 | if ( |
||
| 281 | array_key_exists('facility', $this->logconfig) |
||
| 282 | && ($this->logconfig['facility'] !== $defaultFacility) |
||
| 283 | ) { |
||
| 284 | Logger::warning( |
||
| 285 | 'F-ticks syslog facility differs from global config which may cause' |
||
| 286 | . ' SimpleSAMLphp\'s logging to behave inconsistently' |
||
| 287 | ); |
||
| 288 | } |
||
| 289 | if ( |
||
| 290 | array_key_exists('processname', $this->logconfig) |
||
| 291 | && ($this->logconfig['processname'] !== $defaultProcessName) |
||
| 292 | ) { |
||
| 293 | Logger::warning( |
||
| 294 | 'F-ticks syslog processname differs from global config which may cause' |
||
| 295 | . ' SimpleSAMLphp\'s logging to behave inconsistently' |
||
| 296 | ); |
||
| 423 |