| Conditions | 14 |
| Paths | 768 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 declare(strict_types=1); |
||
| 51 | public function validate() |
||
| 52 | { |
||
| 53 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 54 | $configHandler = \xoops_getHandler('config'); |
||
| 55 | //$xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER); |
||
| 56 | $xoopsConfigUser = []; |
||
| 57 | $criteria = new \Criteria('conf_catid', 2); |
||
| 58 | $myConfigs = $configHandler->getConfigs($criteria); |
||
| 59 | foreach ($myConfigs as $myConf) { |
||
| 60 | $xoopsConfigUser[$myConf->getVar('conf_name')] = $myConf->getVar('conf_value'); |
||
| 61 | } |
||
| 62 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 63 | |||
| 64 | switch ($xoopsConfigUser['uname_test_level']) { |
||
| 65 | case 0: |
||
| 66 | // strict |
||
| 67 | $restriction = '/[^a-zA-Z0-9\_\-]/'; |
||
| 68 | break; |
||
| 69 | case 1: |
||
| 70 | // medium |
||
| 71 | $restriction = '/[^a-zA-Z0-9\_\-\<\>\,\.\$\%\#\@\!\\\'\"]/'; |
||
| 72 | break; |
||
| 73 | case 2: |
||
| 74 | // loose |
||
| 75 | $restriction = '/[\000-\040]/'; |
||
| 76 | break; |
||
| 77 | } |
||
| 78 | |||
| 79 | if (empty($this->uname) || \preg_match($restriction, $this->uname)) { |
||
|
|
|||
| 80 | $this->setError(\_XHELP_MESSAGE_INVALID); |
||
| 81 | } |
||
| 82 | if (mb_strlen($this->uname) > $xoopsConfigUser['maxuname']) { |
||
| 83 | $this->setError(\sprintf(\_XHELP_MESSAGE_LONG, $xoopsConfigUser['maxuname'])); |
||
| 84 | } |
||
| 85 | if (mb_strlen($this->uname) < $xoopsConfigUser['minuname']) { |
||
| 86 | $this->setError(\sprintf(\_XHELP_MESSAGE_SHORT, $xoopsConfigUser['minuname'])); |
||
| 87 | } |
||
| 88 | foreach ($xoopsConfigUser['bad_unames'] as $bu) { |
||
| 89 | if (!empty($bu) && \preg_match('/' . $bu . '/i', $this->uname)) { |
||
| 90 | $this->setError(\_XHELP_MESSAGE_RESERVED); |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | if (mb_strrpos($this->uname, ' ') > 0) { |
||
| 95 | $this->setError(\_XHELP_MESSAGE_NO_SPACES); |
||
| 96 | } |
||
| 97 | $sql = 'SELECT COUNT(*) FROM ' . $xoopsDB->prefix('users') . " WHERE uname='" . \addslashes($this->uname) . "'"; |
||
| 98 | $result = $xoopsDB->query($sql); |
||
| 99 | [$count] = $xoopsDB->fetchRow($result); |
||
| 100 | if ($count > 0) { |
||
| 101 | $this->setError(\_XHELP_MESSAGE_UNAME_TAKEN); |
||
| 102 | } |
||
| 105 |