Completed
Push — master ( 3bdf28...70943d )
by Nate
02:14
created

CompanyContactsCriteria   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 100
ccs 0
cts 51
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getContactId() 0 7 2
A findContactId() 0 4 1
A setContactId() 0 5 1
A all() 0 12 1
A add() 0 13 1
A remove() 0 13 1
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 CompanyContactsCriteria extends AbstractCriteria
19
{
20
    use ConnectionTrait,
21
        CacheTrait,
22
        IdAttributeTrait;
23
24
    /**
25
     * @var string|null
26
     */
27
    protected $contactId;
28
29
    /**
30
     * @return string
31
     * @throws \Exception
32
     */
33
    public function getContactId(): string
34
    {
35
        if (null === ($id = $this->findContactId())) {
36
            throw new \Exception("Invalid Contact Id");
37
        }
38
        return (string)$id;
39
    }
40
41
    /**
42
     * @return string|null
43
     */
44
    public function findContactId()
45
    {
46
        return $this->contactId;
47
    }
48
49
    /**
50
     * @param string|null $id
51
     * @return $this
52
     */
53
    public function setContactId(string $id = null)
54
    {
55
        $this->contactId = $id;
56
        return $this;
57
    }
58
59
    /**
60
     * @param array $criteria
61
     * @param array $config
62
     * @return ResponseInterface
63
     * @throws \Exception
64
     */
65
    public function all(array $criteria = [], array $config = []): ResponseInterface
66
    {
67
        $this->populate($criteria);
68
69
        return CompanyContacts::all(
70
            $this->getId(),
71
            $this->getConnection(),
72
            $this->getCache(),
73
            $this->getLogger(),
74
            $config
75
        );
76
    }
77
78
    /**
79
     * @param array $criteria
80
     * @param array $config
81
     * @return ResponseInterface
82
     * @throws \Exception
83
     */
84
    public function add(array $criteria = [], array $config = []): ResponseInterface
85
    {
86
        $this->populate($criteria);
87
88
        return CompanyContacts::add(
89
            $this->getId(),
90
            $this->getContactId(),
91
            $this->getConnection(),
92
            $this->getCache(),
93
            $this->getLogger(),
94
            $config
95
        );
96
    }
97
98
    /**
99
     * @param array $criteria
100
     * @param array $config
101
     * @return ResponseInterface
102
     * @throws \Exception
103
     */
104
    public function remove(array $criteria = [], array $config = []): ResponseInterface
105
    {
106
        $this->populate($criteria);
107
108
        return CompanyContacts::remove(
109
            $this->getId(),
110
            $this->getContactId(),
111
            $this->getConnection(),
112
            $this->getCache(),
113
            $this->getLogger(),
114
            $config
115
        );
116
    }
117
}
118