PopulateElementErrorsFromResponse   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 5
dl 0
loc 31
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 22 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipbox/hubspot/blob/master/LICENSE.md
6
 * @link       https://github.com/flipbox/hubspot
7
 */
8
9
namespace flipbox\craft\hubspot\transformers;
10
11
use craft\base\Element;
12
use craft\base\ElementInterface;
13
use craft\helpers\Json;
14
use flipbox\craft\hubspot\fields\ObjectsFieldInterface;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class PopulateElementErrorsFromResponse
22
{
23
    /**
24
     * @param ResponseInterface $response
25
     * @param ElementInterface $element
26
     * @param ObjectsFieldInterface $field
27
     * @return ElementInterface
28
     */
29
    public function __invoke(
30
        ResponseInterface $response,
31
        ElementInterface $element,
32
        ObjectsFieldInterface $field
33
    ): ElementInterface {
34
        /** @var Element $element */
35
36
        $data = Json::decodeIfJson(
37
            $response->getBody()->getContents()
38
        );
39
40
        $errors = call_user_func_array(
41
            new InterpretResponseErrors(),
42
            [
43
                $data
44
            ]
45
        );
46
47
        $element->addErrors($errors);
48
49
        return $element;
50
    }
51
}
52