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