Passed
Pull Request — main (#3)
by Daryl
02:28
created

Base   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 50
ccs 22
cts 22
cp 1
rs 10
c 2
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A extraArgs() 0 3 1
A __call() 0 13 3
A setState() 0 9 3
A __construct() 0 3 1
A parseArgs() 0 9 3
1
<?php
2
3
namespace Clubdeuce\Tessitura\Base;
4
5
class Base {
6
    protected array $_extraArgs = [];
7
8 67
    public function __construct(array $args = [])
9
    {
10 67
        $this->setState($args);
11
    }
12
13 67
    protected function setState(array $args = []): void
14
    {
15 67
        foreach ($args as $key => $value) {
16 63
            $property = "_{$key}";
17
18 63
            if (property_exists($this, $property)) {
19 26
                $this->{$property} = $value;
20
            } else {
21 52
                $this->_extraArgs[$key] = $value;
22
            }
23
        }
24
    }
25
26 6
    public function __call(string $name, array $args = []): mixed
27
    {
28 6
        $property = "_{$name}";
29
30 6
        if (property_exists($this, $property)) {
31 4
            return $this->{$property};
32
        }
33
34 2
        if (isset($this->_extraArgs[$name])) {
35 2
            return $this->_extraArgs[$name];
36
        }
37
38 1
        return false;
39
    }
40
41 17
    public function parseArgs(array $args = [], array $defaults = []): array
42
    {
43 17
        foreach ($defaults as $key => $value) {
44 17
            if (!isset($args[$key])) {
45 17
                $args[$key] = $value;
46
            }
47
        }
48
49 17
        return $args;
50
    }
51
52 9
    public function extraArgs(): array
53
    {
54 9
        return $this->_extraArgs;
55
    }
56
}