Passed
Branch master (6d737b)
by Laurens
01:46
created

AbstractFactory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 50
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A extractStringOrNull() 0 3 1
A extractString() 0 3 1
A extractInteger() 0 3 1
A extractBoolean() 0 3 1
A extractArrayOrNull() 0 3 1
A extractOrNull() 0 7 2
A extractFloat() 0 3 1
A extractDateTimeImmutableOrNull() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\NestApi\Client\__shared;
6
7
use DateTimeImmutable;
8
9
abstract class AbstractFactory
10
{
11 10
    protected function extractString(string $key, array $data): ?string
12
    {
13 10
        return $data[$key];
14
    }
15
16 4
    protected function extractStringOrNull(string $key, array $data): ?string
17
    {
18 4
        return $this->extractOrNull($key, $data);
19
    }
20
21 2
    protected function extractInteger(string $key, array $data): int
22
    {
23 2
        return (int)$data[$key];
24
    }
25
26 2
    protected function extractFloat(string $key, array $data): float
27
    {
28 2
        return (float)$data[$key];
29
    }
30
31 10
    protected function extractBoolean(string $key, array $data): bool
32
    {
33 10
        return (bool)$this->extractOrNull($key, $data);
34
    }
35
36 6
    protected function extractArrayOrNull(string $key, array $data): ?array
37
    {
38 6
        return $this->extractOrNull($key, $data);
39
    }
40
41 4
    protected function extractDateTimeImmutableOrNull(string $key, array $data): ?DateTimeImmutable
42
    {
43 4
        $dateTime = $this->extractStringOrNull($key, $data);
44
45 4
        if ($dateTime) {
46 2
            return new DateTimeImmutable($dateTime);
47
        }
48
49 3
        return null;
50
    }
51
52 10
    private function extractOrNull(string $key, array $data)
53
    {
54 10
        if (array_key_exists($key, $data)) {
55 10
            return $data[$key];
56
        }
57
58 7
        return null;
59
    }
60
}
61