Completed
Push — develop ( 1d947e...a9d8b7 )
by Nate
05:38
created

ContactLists   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCriteria() 0 4 1
A read() 0 14 1
A readPipeline() 0 19 1
A readByCriteria() 0 8 1
A readPipelineByCriteria() 0 10 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\hubspot\services\resources;
10
11
use craft\base\ElementInterface;
12
use flipbox\hubspot\connections\ConnectionInterface;
13
use flipbox\hubspot\criteria\ResourceCriteriaInterface;
14
use flipbox\hubspot\criteria\ContactListCriteria;
15
use flipbox\hubspot\fields\Resources;
16
use flipbox\hubspot\helpers\TransformerHelper;
17
use flipbox\hubspot\pipeline\Resource;
18
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
19
use Flipbox\Relay\HubSpot\Builder\Resources\ContactList\Read;
20
use League\Pipeline\PipelineBuilderInterface;
21
use Psr\SimpleCache\CacheInterface;
22
use yii\base\Component;
23
24
25
/**
26
 * @author Flipbox Factory <[email protected]>
27
 * @since 1.0.0
28
 */
29
class ContactLists extends Component
30
{
31
    use traits\HubSpotIdTrait,
32
        traits\TransformElementIdTrait;
33
34
    /**
35
     * The HubSpot Resource name
36
     */
37
    const HUBSPOT_RESOURCE = 'contactLists';
38
39
    /**
40
     * @inheritdoc
41
     * @return ContactListCriteria
42
     */
43
    public function getCriteria(array $criteria = []): ResourceCriteriaInterface
44
    {
45
        return new ContactListCriteria($criteria);
46
    }
47
48
    /*******************************************
49
     * READ/GET
50
     *******************************************/
51
52
    /**
53
     * @param string $id
54
     * @param ConnectionInterface $connection
55
     * @param CacheInterface $cache
56
     * @param TransformerCollectionInterface|null $transformer
57
     * @param mixed|null $source
58
     * @return mixed
59
     */
60
    public function read(
61
        $id,
62
        ConnectionInterface $connection,
63
        CacheInterface $cache,
64
        TransformerCollectionInterface $transformer = null,
65
        $source = null
66
    ) {
67
        return $this->readPipeline(
68
            $id,
69
            $connection,
70
            $cache,
71
            $transformer
72
        )($source);
73
    }
74
75
    /**
76
     * @param string $id
77
     * @param ConnectionInterface $connection
78
     * @param CacheInterface $cache
79
     * @param TransformerCollectionInterface|null $transformer
80
     * @return Resource
81
     */
82
    public function readPipeline(
83
        $id,
84
        ConnectionInterface $connection,
85
        CacheInterface $cache,
86
        TransformerCollectionInterface $transformer = null
87
    ): PipelineBuilderInterface {
88
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
89
            'resource' => [Read::class]
90
        ]);
91
92
        return (new Resource(
93
            (new Read(
94
                $id,
95
                $connection,
96
                $cache
97
            ))->build(),
98
            $transformer
99
        ));
100
    }
101
102
    /**
103
     * @inheritdoc
104
     * @return mixed
105
     */
106
    public function readByCriteria(
107
        ResourceCriteriaInterface $criteria,
108
        $source = null
109
    ) {
110
        return $this->readPipelineByCriteria(
111
            $criteria
112
        )($source);
113
    }
114
115
    /**
116
     * @param ResourceCriteriaInterface $criteria
117
     * @return PipelineBuilderInterface
118
     */
119
    public function readPipelineByCriteria(
120
        ResourceCriteriaInterface $criteria
121
    ): PipelineBuilderInterface {
122
        return $this->readPipeline(
123
            $criteria->getId(),
124
            $criteria->getConnection(),
125
            $criteria->getCache(),
126
            $criteria->getTransformer()
127
        );
128
    }
129
}
130