Test Failed
Push — master ( 92951c...6d737b )
by Laurens
04:18
created

AbstractFactory   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 50
ccs 16
cts 20
cp 0.8
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 extractArrayOrNull() 0 3 1
A extractBoolean() 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 9
    protected function extractString(string $key, array $data): ?string
12
    {
13 9
        return $data[$key];
14
    }
15
16 3
    protected function extractStringOrNull(string $key, array $data): ?string
17
    {
18 3
        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
    protected function extractFloat(string $key, array $data): float
27
    {
28
        return (float)$data[$key];
29
    }
30
31 2
    protected function extractBoolean(string $key, array $data): bool
32
    {
33 2
        return (bool)$this->extractOrNull($key, $data);
34
    }
35
36
    protected function extractArrayOrNull(string $key, array $data): ?array
37
    {
38
        return $this->extractOrNull($key, $data);
39
    }
40
41 9
    protected function extractDateTimeImmutableOrNull(string $key, array $data): ?DateTimeImmutable
42
    {
43 9
        $dateTime = $this->extractStringOrNull($key, $data);
44
45
        if ($dateTime) {
46 6
            return new DateTimeImmutable($dateTime);
47
        }
48 6
49
        return null;
50
    }
51 3
52
    private function extractOrNull(string $key, array $data)
53 3
    {
54
        if (array_key_exists($key, $data)) {
55 3
            return $data[$key];
56 1
        }
57
58
        return null;
59 3
    }
60
}
61