Passed
Push — master ( 7cd6c5...dd963e )
by Laurens
04:05
created

AbstractFactory::extract()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Werkspot\KvkApi\Client\Factory;
6
7
abstract class AbstractFactory
8
{
9 22
    protected function extractStringOrNull(string $key, array $data): ?string
10
    {
11 22
        return $this->extract($key, $data);
12
    }
13
14 19
    protected function extractIntegerOrNull(string $key, array $data): ?int
15
    {
16 19
        return (int) $this->extract($key, $data) ?? null;
17
    }
18
19 16
    protected function extractFloatOrNull(string $key, array $data): ?float
20
    {
21 16
        return (float) $this->extract($key, $data) ?? null;
22
    }
23
24 18
    protected function extractBoolean(string $key, array $data): bool
25
    {
26 18
        return (bool) $this->extract($key, $data);
27
    }
28
29 18
    protected function extractArrayOrNull(string $key, array $data): ?array
30
    {
31 18
        return $this->extract($key, $data);
32
    }
33
34 22
    private function extract(string $key, array $data)
35
    {
36 22
        if (array_key_exists($key, $data)) {
37 22
            return $data[$key];
38
        }
39
40 18
        return null;
41
    }
42
}
43