Completed
Push — master ( 7d4223...27be2f )
by Sergey
08:26 queued 05:47
created

HasVisibilityList   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 0
loc 124
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
getResource() 0 1 ?
postResourceJson() 0 1 ?
deleteResource() 0 1 ?
A getWhiteList() 0 4 1
A getBlackList() 0 4 1
A addToWhiteList() 0 4 1
A addToBlackList() 0 4 1
A addVisibilityItem() 0 12 2
A removeFromWhiteList() 0 7 1
A clearWhiteList() 0 4 1
A removeFromBlackList() 0 7 1
A clearBlackList() 0 4 1
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\Traits;
4
5
trait HasVisibilityList
6
{
7
    /**
8
     * @param string $verb
9
     * @param array $params
10
     * @return mixed
11
     */
12
    abstract public function getResource($verb = '', array $params = []);
13
14
    /**
15
     * @param string $verb
16
     * @param array $params
17
     * @return mixed
18
     */
19
    abstract protected function postResourceJson($verb = '', array $params = []);
20
21
    /**
22
     * @param string $verb
23
     * @param array $params
24
     * @return array|null
25
     */
26
    abstract protected function deleteResource($verb = '', $params = []);
27
28
    /**
29
     * @param string $id
30
     * @return array
31
     */
32
    public function getWhiteList($id)
33
    {
34
        return $this->getResource($id .'/whitelist');
35
    }
36
37
    /**
38
     * @param string $id
39
     * @return array
40
     */
41
    public function getBlackList($id)
42
    {
43
        return $this->getResource($id .'/blacklist');
44
    }
45
46
    /**
47
     * @param string $resumeId
48
     * @param string|array $companyId
49
     * @return mixed
50
     */
51
    public function addToWhiteList($resumeId, $companyId)
52
    {
53
        return $this->addVisibilityItem($resumeId, $companyId, 'whitelist');
54
    }
55
56
    /**
57
     * @param string $resumeId
58
     * @param string|array $companyId
59
     * @return mixed
60
     */
61
    public function addToBlackList($resumeId, $companyId)
62
    {
63
        return $this->addVisibilityItem($resumeId, $companyId, 'blacklist');
64
    }
65
66
    /**
67
     * @param string $resumeId
68
     * @param string|array $companyId
69
     * @param string $list
70
     * @return array
71
     */
72
    protected function addVisibilityItem($resumeId, $companyId, $list)
73
    {
74
        $companyId = is_array($companyId) ? $companyId : [$companyId];
75
76
        $companies = array_map(
77
            function ($company) {
78
                return ['id' => (string)$company];
79
            }, $companyId
80
        );
81
82
        return $this->postResourceJson($resumeId. "/" . $list, ['items' => $companies]);
83
    }
84
85
    /**
86
     * @param string $resumeId
87
     * @param string $companyId
88
     * @return array|null
89
     */
90
    public function removeFromWhiteList($resumeId, $companyId)
91
    {
92
        return $this->deleteResource(
93
            $resumeId . '/whitelist/employer',
94
            ['id' => $companyId]
95
        );
96
    }
97
98
    /**
99
     * @param string $resumeId
100
     * @return array|null
101
     */
102
    public function clearWhiteList($resumeId)
103
    {
104
        return $this->deleteResource($resumeId . '/whitelist/');
105
    }
106
107
    /**
108
     * @param string $resumeId
109
     * @param string $companyId
110
     * @return array|null
111
     */
112
    public function removeFromBlackList($resumeId, $companyId)
113
    {
114
        return $this->deleteResource(
115
            $resumeId . '/blacklist/employer',
116
            ['id' => $companyId]
117
        );
118
    }
119
120
    /**
121
     * @param string $resumeId
122
     * @return array|null
123
     */
124
    public function clearBlackList($resumeId)
125
    {
126
        return $this->delete($resumeId . '/blacklist/');
0 ignored issues
show
Bug introduced by
The method delete() does not exist on seregazhuk\HeadHunterApi\Traits\HasVisibilityList. Did you maybe mean deleteResource()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
127
    }
128
}