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

AbstractFactory::extractFloatOrNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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