Row::isNull()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace BasePatterns\RecordSet;
6
7
use InvalidArgumentException;
8
9
class Row
10
{
11
    private array $row;
12
13
    private array $changes = [];
14
15 4
    public function __construct(array $row)
16
    {
17 4
        $this->row = $row;
18 4
    }
19
20
    public function isNull(string $column): bool
21
    {
22
        return $this->exists($column)
23
            && $this->row[$column] === null;
24
    }
25
26 3
    public function exists(string $column): bool
27
    {
28 3
        return \array_key_exists($column, $this->row);
29
    }
30
31 3
    public function __get(string $name)
32
    {
33 3
        if ($this->exists($name)) {
34 3
            return $this->row[$name];
35
        }
36
37
        throw new InvalidArgumentException(
38
            sprintf("Column with name `%s` does not exist.", $name)
39
        );
40
    }
41
42 1
    public function __set(string $name, $value): void
43
    {
44 1
        if ($this->exists($name)) {
45 1
            $this->row[$name] = $value;
46
47 1
            $this->changes[$name] = $value;
48
49 1
            return;
50
        }
51
52
        throw new InvalidArgumentException(
53
            \sprintf("Column with name `%s` does not exist.", $name)
54
        );
55
    }
56
57 1
    public function hasChanges(): bool
58
    {
59 1
        return !empty($this->changes);
60
    }
61
62 1
    public function getChanges()
63
    {
64 1
        return $this->changes;
65
    }
66
}
67