Conditions | 10 |
Paths | 6 |
Total Lines | 39 |
Code Lines | 25 |
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 |
||
36 | public function getHeader() : string |
||
37 | { |
||
38 | $reportOnly = ''; |
||
39 | if($this->reportOnly) { |
||
40 | $reportOnly = '-Report-Only'; |
||
41 | } |
||
42 | |||
43 | $constructedPolicy = "Content-Security-Policy{$reportOnly}: "; |
||
44 | |||
45 | foreach ($this->policy as $item => $values) { |
||
46 | $constructedPolicy .= $item . ' '; |
||
47 | |||
48 | if (count($values) > 0) { |
||
49 | foreach ($values as $value) { |
||
50 | switch ($value) { |
||
51 | case 'none': |
||
52 | case 'self': |
||
53 | case 'strict-dynamic': |
||
54 | $constructedPolicy .= "'{$value}' "; |
||
55 | break; |
||
56 | case 'nonce': |
||
57 | if($this->nonce !== null) { |
||
58 | $constructedPolicy .= "'nonce-{$this->nonce}' "; |
||
59 | } |
||
60 | break; |
||
61 | default: |
||
62 | $constructedPolicy .= $value . ' '; |
||
63 | break; |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | else { |
||
68 | $constructedPolicy .= "'none' "; |
||
69 | } |
||
70 | |||
71 | $constructedPolicy .= '; '; |
||
72 | } |
||
73 | |||
74 | return $constructedPolicy; |
||
75 | } |
||
77 |