UserAttributesTrait::hasAttribute()   A
last analyzed

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 1
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
    private Collection $attributes;
22
23
    public function getAttributes(): Collection
24
    {
25
        return $this->attributes;
26
    }
27
28
    public function getAttributeValue(string $name): string
29
    {
30
        return $this->getAttributes()->offsetExists($name) ? $this->getAttributes()->get($name)->getValue() : '';
31
    }
32
33
    public function setAttributes(ArrayCollection $attributes): self
34
    {
35
        $this->attributes = $attributes;
36
37
        return $this;
38
    }
39
40
    /**
41
     * @param mixed $value
42
     */
43
    public function setAttribute(string $name, $value): self
44
    {
45
        if (isset($this->attributes[$name])) {
46
            $this->attributes[$name]->setValue($value);
47
        } else {
48
            $this->attributes[$name] = new UserAttribute($this, $name, $value);
49
        }
50
51
        return $this;
52
    }
53
54
    public function delAttribute(string $name): self
55
    {
56
        if (isset($this->attributes[$name])) {
57
            $this->attributes->remove($name);
58
        }
59
60
        return $this;
61
    }
62
63
    public function hasAttribute(string $name): bool
64
    {
65
        return $this->attributes->containsKey($name);
66
    }
67
}
68