ContactListContactsCriteria::getVids()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/hubspot/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/hubspot
7
 */
8
9
namespace Flipbox\HubSpot\Criteria;
10
11
use Flipbox\HubSpot\Resources\ContactListContacts;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
class ContactListContactsCriteria extends AbstractCriteria
19
{
20
    use ConnectionTrait,
21
        CacheTrait,
22
        IdAttributeTrait;
23
24
    /**
25
     * @var array|null
26
     */
27
    protected $vids;
28
    /**
29
     * @var array|null
30
     */
31
    protected $emails;
32
33
    /**
34
     * @return array
35
     * @throws \Exception
36
     */
37
    public function getVids(): array
38
    {
39
        if (null === ($ids = $this->findVids())) {
40
            throw new \Exception("Invalid Contact Ids");
41
        }
42
        return (array)$ids;
43
    }
44
45
    /**
46
     * @return array|null
47
     */
48
    public function findVids()
49
    {
50
        return $this->vids;
51
    }
52
53
    /**
54
     * @param array|null $ids
55
     * @return $this
56
     */
57
    public function setVids(array $ids = null)
58
    {
59
        $this->vids = $ids;
60
        return $this;
61
    }
62
63
    /**
64
     * @return array
65
     * @throws \Exception
66
     */
67
    public function getEmails(): array
68
    {
69
        if (null === ($emails = $this->findEmails())) {
70
            throw new \Exception("Invalid Contact Emails");
71
        }
72
        return (array)$emails;
73
    }
74
75
    /**
76
     * @return array|null
77
     */
78
    public function findEmails()
79
    {
80
        return $this->emails;
81
    }
82
83
    /**
84
     * @param array|null $emails
85
     * @return $this
86
     */
87
    public function setEmails(array $emails = null)
88
    {
89
        $this->emails = $emails;
90
        return $this;
91
    }
92
93
    /**
94
     * @return array
95
     */
96
    public function getPayload(): array
97
    {
98
        return array_filter(
99
            [
100
                'vids' => array_filter($this->findVids()),
101
                'emails' => array_filter($this->findEmails())
102
            ]
103
        );
104
    }
105
106
    /**
107
     * @param array $criteria
108
     * @param array $config
109
     * @return ResponseInterface
110
     * @throws \Exception
111
     */
112
    public function all(array $criteria = [], array $config = []): ResponseInterface
113
    {
114
        $this->populate($criteria);
115
116
        return ContactListContacts::all(
117
            $this->getId(),
118
            $this->getConnection(),
119
            $this->getCache(),
120
            $this->getLogger(),
121
            $config
122
        );
123
    }
124
125
    /**
126
     * @param array $criteria
127
     * @param array $config
128
     * @return ResponseInterface
129
     * @throws \Exception
130
     */
131
    public function add(array $criteria = [], array $config = []): ResponseInterface
132
    {
133
        $this->populate($criteria);
134
135
        return ContactListContacts::add(
136
            $this->getId(),
137
            $this->getPayload(),
138
            $this->getConnection(),
139
            $this->getCache(),
140
            $this->getLogger(),
141
            $config
142
        );
143
    }
144
145
    /**
146
     * @param array $criteria
147
     * @param array $config
148
     * @return ResponseInterface
149
     * @throws \Exception
150
     */
151
    public function remove(array $criteria = [], array $config = []): ResponseInterface
152
    {
153
        $this->populate($criteria);
154
155
        return ContactListContacts::remove(
156
            $this->getId(),
157
            $this->getPayload(),
158
            $this->getConnection(),
159
            $this->getCache(),
160
            $this->getLogger(),
161
            $config
162
        );
163
    }
164
}
165