Conditions | 18 |
Paths | 16 |
Total Lines | 69 |
Code Lines | 36 |
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 |
||
29 | protected function setXssProtection(): void |
||
30 | { |
||
31 | $xssProtectionOptions = $this->getOption('xss_protection'); |
||
|
|||
32 | |||
33 | $xssFilter = new Xss(); |
||
34 | |||
35 | if ($xssProtectionOptions['post']) { |
||
36 | $this->kernel->setClosure('xss_post', function() use ($xssFilter) { |
||
37 | if (!empty($_POST)) { |
||
38 | foreach (array_keys($_POST) as $k) { |
||
39 | $_POST[$k] = $xssFilter->clean($_POST[$k]); |
||
40 | } |
||
41 | } |
||
42 | }); |
||
43 | } |
||
44 | |||
45 | if ($xssProtectionOptions['get']) { |
||
46 | $this->kernel->setClosure('xss_get', function() use ($xssFilter) { |
||
47 | if (!empty($_GET)) { |
||
48 | foreach (array_keys($_GET) as $k) { |
||
49 | $_GET[$k] = $xssFilter->clean($_GET[$k]); |
||
50 | } |
||
51 | } |
||
52 | }); |
||
53 | } |
||
54 | |||
55 | if ($xssProtectionOptions['cookie']) { |
||
56 | $this->kernel->setClosure('xss_cookie', function() use ($xssFilter) { |
||
57 | if (!empty($_COOKIE)) { |
||
58 | foreach (array_keys($_COOKIE) as $k) { |
||
59 | $_COOKIE[$k] = $xssFilter->clean($_COOKIE[$k]); |
||
60 | } |
||
61 | } |
||
62 | }); |
||
63 | } |
||
64 | |||
65 | $xssProtectedList = $this->getOption('xss_protected_list'); |
||
66 | |||
67 | if (!empty($xssProtectedList)) { |
||
68 | |||
69 | $this->kernel->setClosure('xss_protection', function() use ($xssFilter, $xssProtectedList) { |
||
70 | |||
71 | foreach ($xssProtectedList as $v) { |
||
72 | $k = $v['variable'] ?? 'undefined'; |
||
73 | |||
74 | switch ($v['type']) { |
||
75 | |||
76 | case 'get': |
||
77 | |||
78 | if (!empty($_GET[$k])) { |
||
79 | $_GET[$k] = $xssFilter->clean($_GET[$k]); |
||
80 | } |
||
81 | break; |
||
82 | |||
83 | case 'post': |
||
84 | |||
85 | if (!empty($_POST[$k])) { |
||
86 | $_POST[$k] = $xssFilter->clean($_POST[$k]); |
||
87 | } |
||
88 | break; |
||
89 | |||
90 | case 'cookie': |
||
91 | |||
92 | if (!empty($_COOKIE[$k])) { |
||
93 | $_COOKIE[$k] = $xssFilter->clean($_COOKIE[$k]); |
||
94 | } |
||
95 | break; |
||
96 | |||
97 | default: |
||
98 | } |
||
104 |