| Conditions | 17 |
| Paths | 193 |
| Total Lines | 48 |
| Code Lines | 29 |
| 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); |
||
| 52 | public function verifyUser(int $uid = -1, $ip = '', int $forum = 0): bool |
||
| 53 | { |
||
| 54 | \error_reporting(\E_ALL); |
||
| 55 | // if user is admin do not suspend |
||
| 56 | if (\newbbIsAdmin($forum)) { |
||
| 57 | return true; |
||
| 58 | } |
||
| 59 | |||
| 60 | $uid = ($uid < 0) ? (\is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0) : (int)$uid; |
||
| 61 | |||
| 62 | $criteria = new \CriteriaCompo(new \Criteria('uid', (int)$uid)); |
||
| 63 | $forumCriteria = new \CriteriaCompo(new \Criteria('forum_id', 0), 'OR'); |
||
| 64 | if (!empty($forum)) { |
||
| 65 | $forumCriteria->add(new \Criteria('forum_id', (int)$forum), 'OR'); |
||
| 66 | } |
||
| 67 | $criteria->add($forumCriteria); |
||
| 68 | $criteria->add(new \Criteria('mod_end', \time(), '>')); |
||
| 69 | |||
| 70 | $matches = $this->getAll($criteria); |
||
| 71 | |||
| 72 | if (0 === (is_countable($matches) ? \count($matches) : 0)) { |
||
| 73 | return true; // no matches |
||
| 74 | } |
||
| 75 | |||
| 76 | if ($uid > 0 && (is_countable($matches) ? \count($matches) : 0) > 0) { |
||
| 77 | return false; // user is banned |
||
| 78 | } |
||
| 79 | // verify possible matches against IP address |
||
| 80 | $ip = empty($ip) ? IPAddress::fromRequest()->asReadable() : $ip; |
||
| 81 | |||
| 82 | foreach ($matches as $modMatch) { |
||
| 83 | $rawModIp = \trim((string) $modMatch->getVar('ip', 'n')); |
||
| 84 | if (empty($rawModIp)) { |
||
| 85 | return false; // banned without IP |
||
| 86 | } |
||
| 87 | $parts = \explode('/', $rawModIp); |
||
| 88 | $modIp = $parts[0]; |
||
| 89 | $checkIp = new IPAddress($modIp); |
||
| 90 | if (false !== $checkIp->asReadable()) { |
||
| 91 | $defaultMask = (6 === $checkIp->ipVersion()) ? 128 : 32; |
||
| 92 | $netMask = isset($parts[1]) ? (int)$parts[1] : $defaultMask; |
||
| 93 | if ($checkIp->sameSubnet($ip, $netMask, $netMask)) { |
||
| 94 | return false; // IP is banned |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | return true; |
||
| 100 | } |
||
| 152 |