DataSource   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 11

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getData() 0 3 1
A unsetValues() 0 7 2
A addData() 0 7 2
A getValue() 0 3 1
A setValue() 0 5 1
A unsetValue() 0 5 1
A setData() 0 9 2
1
<?php
2
/**
3
 * Copyright © Thomas Klein, All rights reserved.
4
 * See LICENSE bundled with this library for license details.
5
 */
6
declare(strict_types=1);
7
8
namespace LogicTree;
9
10
/**
11
 * @api
12
 */
13
class DataSource
14
{
15
    /**
16
     * Associative data array by key pair value
17
     *
18
     * @var array
19
     */
20
    private $data;
21
22
    public function __construct(iterable $data = [])
23
    {
24
        $this->setData($data);
25
    }
26
27
    public function getData(): array
28
    {
29
        return $this->data;
30
    }
31
32
    public function setData(iterable $data): DataSource
33
    {
34
        $this->data = [];
35
36
        foreach ($data as $key => $value) {
37
            $this->setValue($key, $value);
38
        }
39
40
        return $this;
41
    }
42
43
    public function addData(iterable $data): DataSource
44
    {
45
        foreach ($data as $key => $value) {
46
            $this->setValue($key, $value);
47
        }
48
49
        return $this;
50
    }
51
52
    public function getValue(string $key)
53
    {
54
        return $this->data[$key] ?? null;
55
    }
56
57
    public function setValue(string $key, $value): DataSource
58
    {
59
        $this->data[$key] = $value;
60
61
        return $this;
62
    }
63
64
    public function unsetValue(string $key): DataSource
65
    {
66
        unset($this->data[$key]);
67
68
        return $this;
69
    }
70
71
    public function unsetValues(array $keys): DataSource
72
    {
73
        foreach ($keys as $key) {
74
            $this->unsetValue($key);
75
        }
76
77
        return $this;
78
    }
79
}
80