Conditions | 6 |
Paths | 8 |
Total Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 0 |
1 | <?php |
||
40 | public function isTrusted($ip, PdoDatabase $database = null) |
||
41 | { |
||
42 | if (in_array($ip, $this->trustedCache)) { |
||
43 | return true; |
||
44 | } |
||
45 | |||
46 | if (in_array($ip, $this->untrustedCache)) { |
||
47 | return false; |
||
48 | } |
||
49 | |||
50 | if ($database == null) { |
||
51 | $database = gGetDb(); |
||
52 | } |
||
53 | |||
54 | $query = "SELECT COUNT(*) FROM xfftrustcache WHERE ip = :ip;"; |
||
55 | $statement = $database->prepare($query); |
||
56 | $statement->execute(array(":ip" => $ip)); |
||
57 | $result = $statement->fetchColumn(); |
||
58 | $statement->closeCursor(); |
||
59 | |||
60 | if ($result == 0) { |
||
61 | $this->untrustedCache[] = $ip; |
||
62 | return false; |
||
63 | } |
||
64 | |||
65 | if ($result >= 1) { |
||
66 | $this->trustedCache[] = $ip; |
||
67 | return true; |
||
68 | } |
||
69 | |||
70 | // something weird has happened if we've got here. |
||
71 | // default to untrusted. |
||
72 | return false; |
||
73 | } |
||
74 | } |
||
75 |