Test Failed
Push — master ( 286c96...e21ea4 )
by Laurens
01:29
created

AbstractFactory::extractBoolean()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\eCurring\Resource\Factory;
6
7
use DateTimeImmutable;
8
9
abstract class AbstractFactory
10
{
11
//    protected function extractString(string $key, array $data): ?string
12
//    {
13
//        return $data[$key];
14
//    }
15
16
    protected function extractStringOrNull(string $key, array $data): ?string
17
    {
18
        return $this->extractOrNull($key, $data);
19
    }
20
21
    protected function extractInteger(string $key, array $data): int
22
    {
23
        return (int)$data[$key];
24
    }
25
26
    protected function extractFloat(string $key, array $data): float
27
    {
28
        return (float)$data[$key];
29
    }
30
31
    protected function extractBoolean(string $key, array $data): bool
32
    {
33
        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
    protected function extractDateTimeImmutableOrNull(string $key, array $data): ?DateTimeImmutable
42
    {
43
        $dateTime = $this->extractStringOrNull($key, $data);
44
45
        if ($dateTime) {
46
            return new DateTimeImmutable($dateTime);
47
        }
48
49
        return null;
50
    }
51
52
    private function extractOrNull(string $key, array $data)
53
    {
54
        if (array_key_exists($key, $data)) {
55
            return $data[$key];
56
        }
57
58
        return null;
59
    }
60
}
61