HttpDestinationAuthentication   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 41.18%

Importance

Changes 0
Metric Value
wmc 9
eloc 18
dl 0
loc 42
ccs 7
cts 17
cp 0.4118
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 9 4
A __construct() 0 6 2
A fieldDefinitions() 0 4 1
A authType() 0 7 2
1
<?php
2
/**
3
 */
4
5
namespace Commercetools\Core\Model\Extension;
6
7
use Commercetools\Core\Model\Common\JsonObject;
8
9
/**
10
 * @package Commercetools\Core\Model\Extension
11
 *
12
 * @method string getType()
13
 * @method HttpDestinationAuthentication setType(string $type = null)
14
 */
15
class HttpDestinationAuthentication extends JsonObject
16
{
17
    const AUTH_TYPE = null;
18
    const AUTH_AUTHORIZATION_HEADER = 'AuthorizationHeader';
19
    const AUTH_AZURE_FUNCTIONS = 'AzureFunctions';
20
21
    /**
22
     * @inheritDoc
23
     */
24 6
    public function __construct(array $data = [], $context = null)
25
    {
26 6
        if (!is_null(static::AUTH_TYPE)) {
0 ignored issues
show
introduced by
The condition is_null(static::AUTH_TYPE) is always true.
Loading history...
27 4
            $data[static::TYPE] = static::AUTH_TYPE;
28
        }
29 6
        parent::__construct($data, $context);
30 6
    }
31
32 2
    public function fieldDefinitions()
33
    {
34
        return [
35 2
            'type' => [static::TYPE => 'string'],
36
        ];
37
    }
38
39
    protected static function authType($typeId)
40
    {
41
        $types = [
42
            static::AUTH_AUTHORIZATION_HEADER => AuthorizationHeaderAuthentication::class,
43
            static::AUTH_AZURE_FUNCTIONS => AzureFunctionsAuthentication::class,
44
        ];
45
        return isset($types[$typeId]) ? $types[$typeId] : Destination::class;
46
    }
47
48
    public static function fromArray(array $data, $context = null)
49
    {
50
        if (get_called_class() == HttpDestinationAuthentication::class && isset($data[static::TYPE])) {
51
            $className = static::authType($data[static::TYPE]);
52
            if (class_exists($className)) {
53
                return new $className($data, $context);
54
            }
55
        }
56
        return new static($data, $context);
57
    }
58
}
59