AbstractFactory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
wmc 9
eloc 13
dl 0
loc 50
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A extractBoolean() 0 3 1
A extractArrayOrNull() 0 3 1
A extractOrNull() 0 7 2
A extractStringOrNull() 0 3 1
A extractInteger() 0 3 1
A extractFloat() 0 3 1
A extractDateTimeImmutableOrNull() 0 9 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 5
    protected function extractStringOrNull(string $key, array $data): ?string
17
    {
18 5
        return $this->extractOrNull($key, $data);
19
    }
20
21 4
    protected function extractInteger(string $key, array $data): int
22
    {
23 4
        return (int)$data[$key];
24
    }
25
26 1
    protected function extractFloat(string $key, array $data): float
27
    {
28 1
        return (float)$data[$key];
29
    }
30
31 3
    protected function extractBoolean(string $key, array $data): bool
32
    {
33 3
        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 2
    protected function extractDateTimeImmutableOrNull(string $key, array $data): ?DateTimeImmutable
42
    {
43 2
        $dateTime = $this->extractStringOrNull($key, $data);
44
45 2
        if ($dateTime) {
46 1
            return new DateTimeImmutable($dateTime);
47
        }
48
49 2
        return null;
50
    }
51
52 5
    private function extractOrNull(string $key, array $data)
53
    {
54 5
        if (array_key_exists($key, $data)) {
55 5
            return $data[$key];
56
        }
57
58 1
        return null;
59
    }
60
}
61