Passed
Pull Request — master (#264)
by Wilmer
02:50
created

ActiveRelation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord;
6
7
use Yiisoft\Db\Helper\DbArrayHelper;
8
9
use function array_key_exists;
10
11
final class ActiveRelation
12
{
13
    public function __construct(public array $data = [])
14
    {
15
    }
16
17
    public function add(string $key, mixed $value): void
18
    {
19
        $this->data[$key][] = $value;
20
    }
21
22
    public function clear(): void
23
    {
24
        $this->data = [];
25
    }
26
27
    public function get(string $key): mixed
28
    {
29
        return DbArrayHelper::getValueByPath($this->data, $key);
30
    }
31
32
    public function has(string $key): bool
33
    {
34
        return array_key_exists($key, $this->data);
35
    }
36
37
    public function keys(): array
38
    {
39
        return array_keys($this->data);
40
    }
41
42
    public function set(string $key, mixed $value): void
43
    {
44
        ActiveArrayHelper::set($this->data, $key, $value);
45
    }
46
47
    public function remove(string $key): void
48
    {
49
        ActiveArrayHelper::remove($this->data, $key);
50
    }
51
52
    public function toArray(): array
53
    {
54
        return $this->data;
55
    }
56
}
57