| Conditions | 13 |
| Paths | 16 |
| Total Lines | 55 |
| Code Lines | 37 |
| 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 |
||
| 56 | public function getHeader(): string |
||
| 57 | { |
||
| 58 | $reportOnly = ''; |
||
| 59 | if ($this->reportOnly) { |
||
| 60 | $reportOnly = '-Report-Only'; |
||
| 61 | } |
||
| 62 | |||
| 63 | $constructedPolicy = "Content-Security-Policy{$reportOnly}: "; |
||
| 64 | |||
| 65 | foreach ($this->policy as $item => $values) { |
||
| 66 | $constructedPolicy .= $item . ' '; |
||
| 67 | $policyIsSet = false; |
||
| 68 | |||
| 69 | if (count($values) > 0) { |
||
| 70 | foreach ($values as $value) { |
||
| 71 | switch ($value) { |
||
| 72 | case 'none': |
||
| 73 | case 'self': |
||
| 74 | case 'strict-dynamic': |
||
| 75 | $policyIsSet = true; |
||
| 76 | $constructedPolicy .= "'{$value}' "; |
||
| 77 | break; |
||
| 78 | case 'nonce': |
||
| 79 | if ($this->nonce !== null) { |
||
| 80 | $policyIsSet = true; |
||
| 81 | $constructedPolicy .= "'nonce-{$this->nonce}' "; |
||
| 82 | } |
||
| 83 | break; |
||
| 84 | case 'oauth': |
||
| 85 | $policyIsSet = true; |
||
| 86 | $constructedPolicy .= "{$this->configuration->getOauthMediaWikiCanonicalServer()} "; |
||
| 87 | break; |
||
| 88 | default: |
||
| 89 | $policyIsSet = true; |
||
| 90 | $constructedPolicy .= $value . ' '; |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!$policyIsSet) { |
||
| 96 | $constructedPolicy .= "'none' "; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | else { |
||
| 100 | $constructedPolicy .= "'none' "; |
||
| 101 | } |
||
| 102 | |||
| 103 | $constructedPolicy .= '; '; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($this->configuration->getCspReportUri() !== null) { |
||
| 107 | $constructedPolicy .= 'report-uri ' . $this->configuration->getCspReportUri(); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $constructedPolicy; |
||
| 111 | } |
||
| 113 |