Conditions | 10 |
Paths | 33 |
Total Lines | 45 |
Code Lines | 32 |
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 |
||
33 | public function checkServiceURL($service) |
||
34 | { |
||
35 | $isValidService = false; |
||
36 | $legalUrl = 'undefined'; |
||
37 | $configOverride = null; |
||
38 | foreach ($this->mainConfig->getArray('legal_service_urls', []) as $index => $value) { |
||
39 | // Support two styles: 0 => 'https://example' and 'https://example' => [ extra config ] |
||
40 | if (is_int($index)) { |
||
41 | $legalUrl = $value; |
||
42 | $configOverride = null; |
||
43 | } else { |
||
44 | $legalUrl = $index; |
||
45 | $configOverride = $value; |
||
46 | } |
||
47 | if (empty($legalUrl)) { |
||
48 | Logger::warning("Ignoring empty CAS legal service url '$legalUrl'."); |
||
49 | continue; |
||
50 | } |
||
51 | if (!ctype_alnum($legalUrl[0])) { |
||
52 | // Probably a regex. Suppress errors incase the format is invalid |
||
53 | $result = @preg_match($legalUrl, $service); |
||
54 | if ($result === 1) { |
||
55 | $isValidService = true; |
||
56 | break; |
||
57 | } elseif ($result === false) { |
||
58 | Logger::warning("Invalid CAS legal service url '$legalUrl'. Error ".preg_last_error()); |
||
59 | } |
||
60 | } elseif (strpos($service, $legalUrl) === 0) { |
||
61 | $isValidService = true; |
||
62 | break; |
||
63 | } |
||
64 | } |
||
65 | if ($isValidService) { |
||
66 | $serviceConfig = $this->mainConfig->toArray(); |
||
67 | // Return contextual information about which url rule triggered the validation |
||
68 | $serviceConfig['casService'] = [ |
||
69 | 'matchingUrl' => $legalUrl, |
||
70 | 'serviceUrl' => $service, |
||
71 | ]; |
||
72 | if ($configOverride) { |
||
73 | $serviceConfig = array_merge($serviceConfig, $configOverride); |
||
74 | } |
||
75 | return Configuration::loadFromArray($serviceConfig); |
||
76 | } |
||
77 | return null; |
||
78 | } |
||
80 |