| Conditions | 8 |
| Paths | 20 |
| Total Lines | 128 |
| Code Lines | 56 |
| 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 |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Set iptables working folder. |
||
| 300 | * |
||
| 301 | * @return void |
||
| 302 | */ |
||
| 303 | protected function setIptablesWatchingFolder(): void |
||
| 304 | { |
||
| 305 | $iptablesSetting = $this->getOption('config', 'iptables'); |
||
| 306 | $this->kernel->setProperty('iptables_watching_folder', $iptablesSetting['watching_folder']); |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Set the online session limit. |
||
| 311 | * |
||
| 312 | * @return void |
||
| 313 | */ |
||
| 314 | protected function setSessionLimit(): void |
||
| 315 | { |
||
| 316 | $sessionLimitSetting = $this->getOption('online_session_limit'); |
||
| 317 | |||
| 318 | if ($sessionLimitSetting['enable']) { |
||
| 319 | |||
| 320 | $onlineUsers = $sessionLimitSetting['config']['count'] ?? 100; |
||
| 321 | $alivePeriod = $sessionLimitSetting['config']['period'] ?? 300; |
||
| 322 | |||
| 323 | $this->kernel->limitSession($onlineUsers, $alivePeriod); |
||
| 324 | } |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set the cron job. |
||
| 329 | * This is triggered by the pageviews, not system cron job. |
||
| 330 | * |
||
| 331 | * @return void |
||
| 332 | */ |
||
| 333 | protected function setCronJob(): void |
||
| 334 | { |
||
| 335 | if (!$this->status) { |
||
| 336 | return; |
||
| 337 | } |
||
| 338 | |||
| 339 | $cronjobSetting = $this->getOption('reset_circle', 'cronjob'); |
||
| 340 | |||
| 341 | if ($cronjobSetting['enable']) { |
||
| 342 | |||
| 343 | $nowTime = time(); |
||
| 344 | |||
| 345 | $lastResetTime = $cronjobSetting['config']['last_update']; |
||
| 346 | |||
| 347 | if (!empty($lastResetTime) ) { |
||
| 348 | $lastResetTime = strtotime($lastResetTime); |
||
| 349 | } else { |
||
| 350 | // @codeCoverageIgnoreStart |
||
| 351 | $lastResetTime = strtotime(date('Y-m-d 00:00:00')); |
||
| 352 | // @codeCoverageIgnoreEnd |
||
| 353 | } |
||
| 354 | |||
| 355 | if (($nowTime - $lastResetTime) > $cronjobSetting['config']['period']) { |
||
| 356 | |||
| 357 | $updateResetTime = date('Y-m-d 00:00:00'); |
||
| 358 | |||
| 359 | // Update new reset time. |
||
| 360 | $this->setConfig('cronjob.reset_circle.config.last_update', $updateResetTime); |
||
| 361 | $this->updateConfig(); |
||
| 362 | |||
| 363 | // Remove all logs. |
||
| 364 | $this->kernel->driver->rebuild(); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | } |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set the URLs that want to be excluded from Shieldon protection. |
||
| 371 | * |
||
| 372 | * @return void |
||
| 373 | */ |
||
| 374 | protected function setExcludedUrls(): void |
||
| 375 | { |
||
| 376 | $excludedUrls = $this->getOption('excluded_urls'); |
||
| 377 | |||
| 378 | if (!empty($excludedUrls)) { |
||
| 379 | $list = array_column($excludedUrls, 'url'); |
||
| 380 | |||
| 381 | $this->kernel->setExcludedUrls($list); |
||
| 382 | } |
||
| 383 | } |
||
| 384 | |||
| 385 | /** |
||
| 386 | * WWW-Athentication. |
||
| 387 | * |
||
| 388 | * @return void |
||
| 389 | */ |
||
| 390 | protected function setAuthentication(): void |
||
| 391 | { |
||
| 392 | $authenticateList = $this->getOption('www_authenticate'); |
||
| 393 | |||
| 394 | if (is_array($authenticateList)) { |
||
| 395 | $this->add(new Middleware\httpAuthentication($authenticateList)); |
||
| 396 | } |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Apply the denied list and the allowed list to Ip Component. |
||
| 401 | */ |
||
| 402 | protected function applyComponentIpManager() |
||
| 403 | { |
||
| 404 | $ipList = $this->getOption('ip_manager'); |
||
| 405 | |||
| 406 | $allowedList = []; |
||
| 407 | $deniedList = []; |
||
| 408 | |||
| 409 | if (is_array($ipList)) { |
||
| 410 | foreach ($ipList as $ip) { |
||
| 411 | |||
| 412 | if (0 === strpos($this->kernel->getCurrentUrl(), $ip['url']) ) { |
||
| 413 | |||
| 414 | if ('allow' === $ip['rule']) { |
||
| 415 | $allowedList[] = $ip['ip']; |
||
| 416 | } |
||
| 417 | |||
| 418 | if ('deny' === $ip['rule']) { |
||
| 419 | $deniedList[] = $ip['ip']; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | } |
||
| 423 | } |
||
| 424 | |||
| 425 | $this->kernel->component['Ip']->setAllowedItems($allowedList); |
||
| 444 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths