EntityBag::removeField()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 2
rs 10
c 1
b 0
f 0
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