Completed
Push — master ( a92b54...054790 )
by Ehsan
02:50
created

WhiteList::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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