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

AbstractFactory::extractFloatOrNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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