Passed
Push — master ( b808b9...919917 )
by Ehsan
04:54
created

WhiteList::isWhiteListed()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 11
nc 48
nop 0
crap 7
1
<?php
2
3
namespace Botonomous;
4
5
class WhiteList extends AbstractAccessList
6
{
7
    /**
8
     * WhiteList constructor.
9
     *
10
     * @param $request
11
     */
12 12
    public function __construct($request)
13
    {
14 12
        $this->setRequest($request);
15 12
    }
16
17
    /**
18
     * @return bool
19
     */
20 3
    public function isWhiteListed()
21
    {
22 3
        $usernameCheck = true;
23 3
        $userIdCheck = true;
24 3
        $userEmailCheck = true;
25
26 3
        if ($this->isUsernameWhiteListed() === false) {
27 2
            $usernameCheck = false;
28
        }
29
30 3
        if ($this->isUserIdWhiteListed() === false) {
31 2
            $userIdCheck = false;
32
        }
33
34 3
        if ($this->isEmailWhiteListed() === false) {
35 2
            $userEmailCheck = false;
36
        }
37
38 3
        return $usernameCheck === true && $userIdCheck === true && $userEmailCheck === true ? true : false;
39
    }
40
41
    /**
42
     * @return bool
43
     */
44 4
    public function isUsernameWhiteListed()
45
    {
46 4
        return empty($this->findInListByRequestKey('user_name', $this->getShortClassName(), 'username')) ? false : true;
47
    }
48
49
    /**
50
     * @return bool
51
     */
52 4
    public function isUserIdWhiteListed()
53
    {
54 4
        return empty($this->findInListByRequestKey('user_id', $this->getShortClassName(), 'userId')) ? false : true;
55
    }
56
57
    /**
58
     * @return bool
59
     * @return mixed
60
     */
61 6
    public function isEmailWhiteListed()
62
    {
63
        // user_name is set, load the blacklist to start checking
64 6
        $list = $this->getSubAccessControlList($this->getShortClassName());
65
66
        // currently if list is not set we do not check it
67 6
        if (!isset($list['userEmail'])) {
68 1
            return true;
69
        }
70
71 5
        return $this->isEmailInList($list);
72
    }
73
}
74