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

TransformElementPayloadTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 27
c 0
b 0
f 0
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A transformElementPayload() 0 19 2
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\traits;
10
11
use craft\base\ElementInterface;
12
use flipbox\flux\helpers\TransformerHelper;
13
use flipbox\hubspot\fields\Objects;
14
use flipbox\hubspot\HubSpot;
15
use Flipbox\Transform\Factory;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
trait TransformElementPayloadTrait
22
{
23
    /**
24
     * @param ElementInterface $element
25
     * @param Objects $field
26
     * @return array
27
     */
28
    protected function transformElementPayload(
29
        ElementInterface $element,
30
        Objects $field
31
    ): array {
32
33
        $transformer = HubSpot::getInstance()->getTransformers()->find(
34
            TransformerHelper::eventName([$field->object, 'payload']),
35
            get_class($element)
36
        );
37
38
        if ($transformer !== null) {
39
            return (array)Factory::item(
40
                $transformer,
41
                $element
42
            );
43
        }
44
45
        return [];
46
    }
47
}
48