DynamicModelResponse   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 0
loc 21
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 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\craft\hubspot\transformers;
10
11
use craft\helpers\Json;
12
use Psr\Http\Message\ResponseInterface;
13
use yii\base\DynamicModel;
14
15
/**
16
 * @author Flipbox Factory <[email protected]>
17
 * @since 1.0.0
18
 */
19
class DynamicModelResponse
20
{
21
    use TransformResponseErrorsTrait;
22
23
    /**
24
     * @param ResponseInterface $response
25
     * @return DynamicModel
26
     */
27
    public function __invoke(ResponseInterface $response): DynamicModel
28
    {
29
        $data = Json::decodeIfJson(
30
            $response->getBody()->getContents()
31
        );
32
33
        if ($response->getStatusCode() === 200) {
34
            return new DynamicModel(array_keys($data), $data);
35
        }
36
37
        return $this->transformResponseErrors($response, $data);
38
    }
39
}
40