Completed
Push — develop ( 0ca1ab...29c245 )
by Nate
03:14
created

TimelineEvents   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 105
c 0
b 0
f 0
wmc 4
lcom 1
cbo 6
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A upsert() 0 16 1
A upsertPipeline() 0 27 1
A upsertByCriteria() 0 8 1
A readPipelineByCriteria() 0 11 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 flipbox\hubspot\connections\IntegrationConnectionInterface;
12
use flipbox\hubspot\criteria\TimelineEventCriteria;
13
use flipbox\hubspot\helpers\TransformerHelper;
14
use flipbox\hubspot\HubSpot;
15
use flipbox\hubspot\pipeline\Resource;
16
use flipbox\hubspot\transformers\collections\TransformerCollectionInterface;
17
use Flipbox\Relay\HubSpot\Builder\Resources\Timeline\UpsertEvent;
18
use League\Pipeline\PipelineBuilderInterface;
19
use yii\base\Component;
20
21
/**
22
 * @author Flipbox Factory <[email protected]>
23
 * @since 1.0.0
24
 */
25
class TimelineEvents extends Component
26
{
27
    /**
28
     * The HubSpot Resource name
29
     */
30
    const HUBSPOT_RESOURCE = 'timelineEvents';
31
32
    /*******************************************
33
     * UPSERT
34
     *******************************************/
35
36
    /**
37
     * @param string $id
38
     * @param string $typeId
39
     * @param array $payload
40
     * @param IntegrationConnectionInterface $connection
41
     * @param TransformerCollectionInterface|null $transformer
42
     * @param mixed|null $source
43
     * @return mixed
44
     */
45
    public function upsert(
46
        string $id,
47
        string $typeId,
48
        array $payload,
49
        IntegrationConnectionInterface $connection,
50
        TransformerCollectionInterface $transformer = null,
51
        $source = null
52
    ) {
53
        return $this->upsertPipeline(
54
            $id,
55
            $typeId,
56
            $payload,
57
            $connection,
58
            $transformer
59
        )($source);
60
    }
61
62
    /**
63
     * @param string $id
64
     * @param string $typeId
65
     * @param array $payload
66
     * @param IntegrationConnectionInterface $connection
67
     * @param TransformerCollectionInterface|null $transformer
68
     * @return Resource
69
     */
70
    public function upsertPipeline(
71
        string $id,
72
        string $typeId,
73
        array $payload,
74
        IntegrationConnectionInterface $connection,
75
        TransformerCollectionInterface $transformer = null
76
    ): PipelineBuilderInterface {
77
        $transformer = TransformerHelper::populateTransformerCollection($transformer, [
78
            'resource' => [UpsertEvent::class]
79
        ]);
80
81
        $payload['id'] = $id;
82
        $payload['eventTypeId'] = $typeId;
83
84
        $logger = HubSpot::getInstance()->getPsrLogger();
85
86
        return (new Resource(
87
            (new UpsertEvent(
88
                $connection->getAppId(),
89
                $payload,
90
                $connection,
91
                $logger
92
            ))->build(),
93
            $transformer,
94
            $logger
95
        ));
96
    }
97
98
    /**
99
     * @param TimelineEventCriteria $criteria
100
     * @param null $source
101
     * @throws \yii\base\InvalidConfigException
102
     * @return mixed
103
     */
104
    public function upsertByCriteria(
105
        TimelineEventCriteria $criteria,
106
        $source = null
107
    ) {
108
        return $this->readPipelineByCriteria(
109
            $criteria
110
        )($source);
111
    }
112
113
    /**
114
     * @param TimelineEventCriteria $criteria
115
     * @return PipelineBuilderInterface
116
     * @throws \yii\base\InvalidConfigException
117
     */
118
    public function readPipelineByCriteria(
119
        TimelineEventCriteria $criteria
120
    ): PipelineBuilderInterface {
121
        return $this->upsertPipeline(
122
            $criteria->getId(),
123
            $criteria->getTypeId(),
124
            $criteria->getPayload(),
125
            $criteria->getConnection(),
126
            $criteria->getTransformer()
0 ignored issues
show
Bug introduced by
It seems like $criteria->getTransformer() targeting flipbox\hubspot\criteria...Trait::getTransformer() can also be of type object or string; however, flipbox\hubspot\services...vents::upsertPipeline() does only seem to accept null|object<flipbox\hubs...merCollectionInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
127
        );
128
    }
129
}
130