| Conditions | 6 |
| Paths | 9 |
| Total Lines | 51 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 116 | public function xssProtection(): ResponseInterface |
||
| 117 | { |
||
| 118 | $postParams = get_request()->getParsedBody(); |
||
| 119 | |||
| 120 | if ($this->checkPostParamsExist('xss')) { |
||
| 121 | unset_superglobal('xss', 'post'); |
||
| 122 | |||
| 123 | $type = $postParams['type'] ?? ''; |
||
| 124 | $variable = $postParams['variable'] ?? ''; |
||
| 125 | $action = $postParams['action'] ?? ''; |
||
| 126 | |||
| 127 | // The index number in the $xssProtectedList, see below. |
||
| 128 | $order = (int) $postParams['order']; |
||
| 129 | |||
| 130 | // Check variable name. Should be mixed with a-zA-Z and underscore. |
||
| 131 | if (!ctype_alnum(str_replace('_', '', $variable))) { |
||
| 132 | |||
| 133 | // @codeCoverageIgnoreStart |
||
| 134 | // Ignore the `add` process. |
||
| 135 | $action = 'undefined'; |
||
| 136 | // @codeCoverageIgnoreEnd |
||
| 137 | } |
||
| 138 | |||
| 139 | $xssProtectedList = (array) $this->getConfig('xss_protected_list'); |
||
| 140 | |||
| 141 | if ('add' === $action) { |
||
| 142 | if (in_array($type, ['get', 'post', 'cookie'])) { |
||
| 143 | array_push($xssProtectedList, ['type' => $type, 'variable' => $variable]); |
||
| 144 | } |
||
| 145 | } elseif ('remove' === $action) { |
||
| 146 | unset($xssProtectedList[$order]); |
||
| 147 | $xssProtectedList = array_values($xssProtectedList); |
||
| 148 | } |
||
| 149 | |||
| 150 | $this->setConfig('xss_protected_list', $xssProtectedList); |
||
| 151 | |||
| 152 | unset_superglobal('type', 'post'); |
||
| 153 | unset_superglobal('variable', 'post'); |
||
| 154 | unset_superglobal('action', 'post'); |
||
| 155 | unset_superglobal('order', 'post'); |
||
| 156 | |||
| 157 | $this->saveConfig(); |
||
| 158 | } |
||
| 159 | |||
| 160 | $data = []; |
||
| 161 | |||
| 162 | $data['xss_protected_list'] = $this->getConfig('xss_protected_list'); |
||
| 163 | |||
| 164 | $data['title'] = __('panel', 'title_xss_protection', 'XSS Protection'); |
||
| 165 | |||
| 166 | return $this->renderPage('panel/xss_protection', $data); |
||
| 167 | } |
||
| 169 |