Passed
Push — main ( b15a24...935ae5 )
by Axel
04:15
created

UserAttributesTrait::getAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\UsersBundle\Entity;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
19
trait UserAttributesTrait
20
{
21
    
22
    private Collection $attributes;
23
24
    public function getAttributes(): Collection
25
    {
26
        return $this->attributes;
27
    }
28
29
    public function getAttributeValue(string $name): string
30
    {
31
        return $this->getAttributes()->offsetExists($name) ? $this->getAttributes()->get($name)->getValue() : '';
32
    }
33
34
    public function setAttributes(ArrayCollection $attributes): self
35
    {
36
        $this->attributes = $attributes;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @param mixed $value
43
     */
44
    public function setAttribute(string $name, $value): self
45
    {
46
        if (isset($this->attributes[$name])) {
47
            $this->attributes[$name]->setValue($value);
48
        } else {
49
            $this->attributes[$name] = new UserAttribute($this, $name, $value);
50
        }
51
52
        return $this;
53
    }
54
55
    public function delAttribute(string $name): self
56
    {
57
        if (isset($this->attributes[$name])) {
58
            $this->attributes->remove($name);
59
        }
60
61
        return $this;
62
    }
63
64
    public function hasAttribute(string $name): bool
65
    {
66
        return $this->attributes->containsKey($name);
67
    }
68
}
69