Completed
Push — master ( bb722b...3bdf28 )
by Nate
02:16
created

CompanyContactsMutatorCriteria::setContactId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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\CompanyContacts;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 2.0.0
17
 */
18
class CompanyContactsMutatorCriteria extends AbstractCriteria
19
{
20
    use ConnectionTrait,
21
        CacheTrait;
22
23
    /**
24
     * @var string|null
25
     */
26
    protected $companyId;
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $contactId;
32
33
    /**
34
     * @return string
35
     * @throws \Exception
36
     */
37
    public function getCompanyId(): string
38
    {
39
        if (null === ($id = $this->findCompanyId())) {
40
            throw new \Exception("Invalid Company Id");
41
        }
42
        return (string)$id;
43
    }
44
45
    /**
46
     * @return string|null
47
     */
48
    public function findCompanyId()
49
    {
50
        return $this->companyId;
51
    }
52
53
    /**
54
     * @param string|null $id
55
     * @return $this
56
     */
57
    public function setCompanyId(string $id = null)
58
    {
59
        $this->companyId = $id;
60
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     * @throws \Exception
66
     */
67
    public function getContactId(): string
68
    {
69
        if (null === ($id = $this->findContactId())) {
70
            throw new \Exception("Invalid Contact Id");
71
        }
72
        return (string)$id;
73
    }
74
75
    /**
76
     * @return string|null
77
     */
78
    public function findContactId()
79
    {
80
        return $this->contactId;
81
    }
82
83
    /**
84
     * @param string|null $id
85
     * @return $this
86
     */
87
    public function setContactId(string $id = null)
88
    {
89
        $this->contactId = $id;
90
        return $this;
91
    }
92
93
    /**
94
     * @param array $criteria
95
     * @param array $config
96
     * @return ResponseInterface
97
     * @throws \Exception
98
     */
99
    public function add(array $criteria = [], array $config = []): ResponseInterface
100
    {
101
        $this->populate($criteria);
102
103
        return CompanyContacts::add(
104
            $this->getCompanyId(),
105
            $this->getContactId(),
106
            $this->getConnection(),
107
            $this->getCache(),
108
            $this->getLogger(),
109
            $config
110
        );
111
    }
112
113
    /**
114
     * @param array $criteria
115
     * @param array $config
116
     * @return ResponseInterface
117
     * @throws \Exception
118
     */
119
    public function remove(array $criteria = [], array $config = []): ResponseInterface
120
    {
121
        $this->populate($criteria);
122
123
        return CompanyContacts::remove(
124
            $this->getCompanyId(),
125
            $this->getContactId(),
126
            $this->getConnection(),
127
            $this->getCache(),
128
            $this->getLogger(),
129
            $config
130
        );
131
    }
132
}
133