EntityBag   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 46
ccs 23
cts 23
cp 1
rs 10
c 1
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntity() 0 3 1
A setField() 0 10 2
A setEntity() 0 5 1
A removeField() 0 9 2
A setFields() 0 7 2
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 EntityBag extends Transporter
14
{
15
    private Entity $entity;
16
17 1
    public function setEntity(Entity $entity): self
18
    {
19 1
        $this->entity = $entity;
20
21 1
        return $this;
22
    }
23
24 1
    public function getEntity(): Entity
25
    {
26 1
        return $this->entity;
27
    }
28
29 2
    public function setField($field, $value): Transporter
30
    {
31 2
        $set = $this->getEntity()->getAttributeSet();
32 2
        if ($set->hasContainer($field)) {
33 2
            $container = $set->getContainer($field);
34 2
            $valueManager = $container->getValueManager();
35 2
            $valueManager->setValue($value);
36
        }
37
38 2
        return parent::setField($field, $value);
39
    }
40
41 1
    public function removeField($field): void
42
    {
43 1
        $set = $this->getEntity()->getAttributeSet();
44 1
        if ($set->hasContainer($field)) {
45 1
            $set->getContainer($field)
46 1
                ->getValueManager()
47 1
                ->clearRuntime();
48
        }
49 1
        parent::removeField($field);
50
    }
51
52 1
    public function setFields(array $data): self
53
    {
54 1
        foreach ($data as $field => $value) {
55 1
            $this->setField($field, $value);
56
        }
57
58 1
        return $this;
59
    }
60
}
61