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

CreateObjectTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 138
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 138
c 0
b 0
f 0
ccs 0
cts 29
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
rawCreatePipeline() 0 5 ?
rawHttpCreateRelay() 0 5 ?
A create() 0 13 1
A rawCreate() 0 12 1
A createPipeline() 0 11 1
A httpCreateRelay() 0 9 1
A httpCreate() 0 9 1
A rawHttpCreate() 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\builders\ObjectBuilderInterface;
12
use flipbox\hubspot\connections\ConnectionInterface;
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 CreateObjectTrait
23
{
24
    /**
25
     * @param array $payload
26
     * @param ConnectionInterface|null $connection
27
     * @param TransformerCollectionInterface|null $transformer
28
     * @return PipelineBuilderInterface
29
     * @throws \yii\base\InvalidConfigException
30
     */
31
    public abstract function rawCreatePipeline(
32
        array $payload,
33
        ConnectionInterface $connection = null,
34
        TransformerCollectionInterface $transformer = null
35
    ): PipelineBuilderInterface;
36
37
    /**
38
     * @param array $payload
39
     * @param ConnectionInterface|null $connection
40
     * @param CacheInterface|null $cache
41
     * @return callable
42
     * @throws \yii\base\InvalidConfigException
43
     */
44
    public abstract function rawHttpCreateRelay(
45
        array $payload,
46
        ConnectionInterface $connection = null,
47
        CacheInterface $cache = null
48
    ): callable;
49
50
    /**
51
     * @param ObjectBuilderInterface $builder
52
     * @param ConnectionInterface|null $connection
53
     * @param TransformerCollectionInterface|null $transformer
54
     * @param null $source
55
     * @return mixed
56
     * @throws \yii\base\InvalidConfigException
57
     */
58
    public function create(
59
        ObjectBuilderInterface $builder,
60
        ConnectionInterface $connection = null,
61
        TransformerCollectionInterface $transformer = null,
62
        $source = null
63
    ) {
64
        return $this->rawCreate(
65
            $builder->getPayload(),
66
            $connection,
67
            $transformer,
68
            $source
69
        );
70
    }
71
72
    /**
73
     * @param array $payload
74
     * @param ConnectionInterface|null $connection
75
     * @param TransformerCollectionInterface|null $transformer
76
     * @param null $source
77
     * @return mixed
78
     * @throws \yii\base\InvalidConfigException
79
     */
80
    public function rawCreate(
81
        array $payload,
82
        ConnectionInterface $connection = null,
83
        TransformerCollectionInterface $transformer = null,
84
        $source = null
85
    ) {
86
        return $this->rawCreatePipeline(
87
            $payload,
88
            $connection,
89
            $transformer
90
        )($source);
91
    }
92
93
    /**
94
     * @param ObjectBuilderInterface $builder
95
     * @param ConnectionInterface|null $connection
96
     * @param TransformerCollectionInterface|null $transformer
97
     * @return PipelineBuilderInterface
98
     * @throws \yii\base\InvalidConfigException
99
     */
100
    public function createPipeline(
101
        ObjectBuilderInterface $builder,
102
        ConnectionInterface $connection = null,
103
        TransformerCollectionInterface $transformer = null
104
    ): PipelineBuilderInterface {
105
        return $this->rawCreatePipeline(
106
            $builder->getPayload(),
107
            $connection,
108
            $transformer
109
        );
110
    }
111
112
    /**
113
     * @param ObjectBuilderInterface $builder
114
     * @param ConnectionInterface|null $connection
115
     * @return callable
116
     * @throws \yii\base\InvalidConfigException
117
     */
118
    public function httpCreateRelay(
119
        ObjectBuilderInterface $builder,
120
        ConnectionInterface $connection = null
121
    ): callable {
122
        return $this->rawHttpCreateRelay(
123
            $builder->getPayload(),
124
            $connection
125
        );
126
    }
127
128
    /**
129
     * @param ObjectBuilderInterface $builder
130
     * @param ConnectionInterface|null $connection
131
     * @return ResponseInterface
132
     * @throws \yii\base\InvalidConfigException
133
     */
134
    public function httpCreate(
135
        ObjectBuilderInterface $builder,
136
        ConnectionInterface $connection = null
137
    ): ResponseInterface {
138
        return $this->rawHttpCreateRelay(
139
            $builder->getPayload(),
140
            $connection
141
        )();
142
    }
143
144
    /**
145
     * @param array $payload
146
     * @param ConnectionInterface|null $connection
147
     * @return ResponseInterface
148
     * @throws \yii\base\InvalidConfigException
149
     */
150
    public function rawHttpCreate(
151
        array $payload,
152
        ConnectionInterface $connection = null
153
    ): ResponseInterface {
154
        return $this->rawHttpCreateRelay(
155
            $payload,
156
            $connection
157
        )();
158
    }
159
}
160