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

AbstractFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A extractStringOrNull() 0 4 1
A extractIntegerOrNull() 0 4 1
A extractFloatOrNull() 0 4 1
A extractBoolean() 0 4 1
A extractArrayOrNull() 0 4 1
A extract() 0 8 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