Passed
Push — master ( 17e6cc...350d8b )
by Aleksandr
41:29 queued 06:24
created

Transporter   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 21
dl 0
loc 88
ccs 34
cts 34
cp 1
rs 10
c 1
b 0
f 1
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setField() 0 5 1
A getData() 0 3 1
A clear() 0 3 1
A getField() 0 7 2
A __get() 0 3 1
A hasField() 0 3 1
A __unset() 0 3 1
A setData() 0 5 1
A removeField() 0 3 1
A __set() 0 3 1
A __toJson() 0 3 1
A __toString() 0 3 1
A __isset() 0 3 1
A __toObject() 0 3 1
A __toArray() 0 3 1
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 *
5
 * @author    Alex Kuperwood <[email protected]>
6
 * @copyright 2025 Alex Kuperwood
7
 * @license   https://opensource.org/license/mit  The MIT License
8
 */
9
declare(strict_types=1);
10
11
namespace Kuperwood\Eav;
12
13
class Transporter
14
{
15
    private array $data = [];
16
17 1
    public function __get(string $field)
18
    {
19 1
        return $this->getField($field);
20
    }
21
22 1
    public function __set(string $field, $value): void
23
    {
24 1
        $this->setField($field, $value);
25
    }
26
27 1
    public function __isset(string $field): bool
28
    {
29 1
        return $this->hasField($field);
30
    }
31
32 1
    public function __unset(string $field): void
33
    {
34 1
        $this->removeField($field);
35
    }
36
37 1
    public function __toString(): string
38
    {
39 1
        return json_encode($this->data);
40
    }
41
42 1
    public function __toArray(): array
43
    {
44 1
        return $this->data;
45
    }
46
47 1
    public function __toJson(): string
48
    {
49 1
        return json_encode($this->data);
50
    }
51
52 1
    public function __toObject(): object
53
    {
54 1
        return (object) $this->data;
55
    }
56
57 1
    public function setField($field, $value): self
58
    {
59 1
        $this->data[$field] = $value;
60
61 1
        return $this;
62
    }
63
64
    /**
65
     * @param $field
66
     */
67 1
    public function getField($field)
68
    {
69 1
        if (!$this->hasField($field)) {
70 1
            return null;
71
        }
72
73 1
        return $this->data[$field];
74
    }
75
76 1
    public function getData(): array
77
    {
78 1
        return $this->data;
79
    }
80
81 1
    public function setData(array $data): self
82
    {
83 1
        $this->data = $data;
84
85 1
        return $this;
86
    }
87
88 1
    public function hasField($field): bool
89
    {
90 1
        return array_key_exists($field, $this->data);
91
    }
92
93 1
    public function removeField($field): void
94
    {
95 1
        unset($this->data[$field]);
96
    }
97
98 1
    public function clear(): void
99
    {
100 1
        $this->data = [];
101
    }
102
}
103