Completed
Push — develop ( 639fa1...b48ec5 )
by Nate
02:32
created

ReadObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 1
dl 0
loc 139
c 0
b 0
f 0
ccs 0
cts 35
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
rawReadPipeline() 0 6 ?
rawHttpReadRelay() 0 5 ?
A read() 0 11 1
A rawRead() 0 14 1
A readPipeline() 0 10 1
A httpRead() 0 9 1
A rawHttpRead() 0 11 1
A httpReadRelay() 0 9 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\traits;
10
11
use flipbox\hubspot\connections\ConnectionInterface;
12
use flipbox\hubspot\criteria\ObjectCriteriaInterface;
13
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
14
use League\Pipeline\PipelineBuilderInterface;
15
use Psr\Http\Message\ResponseInterface;
16
use Psr\SimpleCache\CacheInterface;
17
18
/**
19
 * @author Flipbox Factory <[email protected]>
20
 * @since 1.0.0
21
 */
22
trait ReadObjectTrait
23
{
24
    /**
25
     * @param $id
26
     * @param ConnectionInterface|null $connection
27
     * @param CacheInterface|null $cache
28
     * @param TransformerCollectionInterface|null $transformer
29
     * @return PipelineBuilderInterface
30
     * @throws \yii\base\InvalidConfigException
31
     */
32
    public abstract function rawReadPipeline(
33
        string $id,
34
        ConnectionInterface $connection = null,
35
        CacheInterface $cache = null,
36
        TransformerCollectionInterface $transformer = null
37
    ): PipelineBuilderInterface;
38
39
    /**
40
     * @param $id
41
     * @param ConnectionInterface|null $connection
42
     * @param CacheInterface|null $cache
43
     * @return callable
44
     * @throws \yii\base\InvalidConfigException
45
     */
46
    public abstract function rawHttpReadRelay(
47
        string $id,
48
        ConnectionInterface $connection = null,
49
        CacheInterface $cache = null
50
    ): callable;
51
52
53
    /**
54
     * @param ObjectCriteriaInterface $criteria
55
     * @param null $source
56
     * @return mixed
57
     * @throws \yii\base\InvalidConfigException
58
     */
59
    public function read(
60
        ObjectCriteriaInterface $criteria,
61
        $source = null
62
    ) {
63
        return $this->rawRead(
64
            $criteria->getId(),
65
            $criteria->getConnection(),
66
            $criteria->getCache(),
67
            $criteria->getTransformer()
68
        )($source);
69
    }
70
71
    /**
72
     * @param $id
73
     * @param ConnectionInterface|null $connection
74
     * @param CacheInterface|null $cache
75
     * @param TransformerCollectionInterface|null $transformer
76
     * @param null $source
77
     * @return mixed
78
     * @throws \yii\base\InvalidConfigException
79
     */
80
    public function rawRead(
81
        string $id,
82
        ConnectionInterface $connection = null,
83
        CacheInterface $cache = null,
84
        TransformerCollectionInterface $transformer = null,
85
        $source = null
86
    ) {
87
        return $this->rawReadPipeline(
88
            $id,
89
            $connection,
90
            $cache,
91
            $transformer
92
        )($source);
93
    }
94
95
    /**
96
     * @param ObjectCriteriaInterface $criteria
97
     * @return PipelineBuilderInterface
98
     * @throws \yii\base\InvalidConfigException
99
     */
100
    public function readPipeline(
101
        ObjectCriteriaInterface $criteria
102
    ): PipelineBuilderInterface {
103
        return $this->rawReadPipeline(
104
            $criteria->getId(),
105
            $criteria->getConnection(),
106
            $criteria->getCache(),
107
            $criteria->getTransformer()
108
        );
109
    }
110
111
112
    /**
113
     * @param ObjectCriteriaInterface $criteria
114
     * @return ResponseInterface
115
     * @throws \yii\base\InvalidConfigException
116
     */
117
    public function httpRead(
118
        ObjectCriteriaInterface $criteria
119
    ): ResponseInterface {
120
        return $this->rawHttpRead(
121
            $criteria->getId(),
122
            $criteria->getConnection(),
123
            $criteria->getCache()
124
        )();
125
    }
126
127
    /**
128
     * @param $id
129
     * @param ConnectionInterface|null $connection
130
     * @param CacheInterface|null $cache
131
     * @return ResponseInterface
132
     * @throws \yii\base\InvalidConfigException
133
     */
134
    public function rawHttpRead(
135
        $id,
136
        ConnectionInterface $connection = null,
137
        CacheInterface $cache = null
138
    ): ResponseInterface {
139
        return $this->rawHttpReadRelay(
140
            $id,
141
            $connection,
142
            $cache
143
        )();
144
    }
145
146
    /**
147
     * @param ObjectCriteriaInterface $criteria
148
     * @return callable
149
     * @throws \yii\base\InvalidConfigException
150
     */
151
    public function httpReadRelay(
152
        ObjectCriteriaInterface $criteria
153
    ): callable {
154
        return $this->rawHttpReadRelay(
155
            $criteria->getId(),
156
            $criteria->getConnection(),
157
            $criteria->getCache()
158
        );
159
    }
160
}
161