UserAttribute   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A setExtra() 0 5 1
A setName() 0 5 1
A setAttribute() 0 6 1
A setUser() 0 5 1
A setValue() 0 5 1
A __construct() 0 4 1
A getName() 0 3 1
A getUser() 0 3 1
A getExtra() 0 3 1
A getValue() 0 3 1
A __toString() 0 3 1
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\DBAL\Types\Types;
17
use Doctrine\ORM\Mapping as ORM;
18
use Symfony\Component\Validator\Constraints as Assert;
19
use Zikula\UsersBundle\Repository\UserAttributeRepository;
20
21
/**
22
 * User attributes store extra information about each user account.
23
 */
24
// #[ORM\Entity(repositoryClass: UserAttributeRepository::class)] TODO remove if unneeded
25
#[ORM\Entity]
26
#[ORM\Table(name: 'nucleos_user__user_attribute')]
27
class UserAttribute
28
{
29
    #[ORM\Id]
30
    #[ORM\ManyToOne(inversedBy: 'attributes')]
31
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
32
    private User $user;
33
34
    #[ORM\Id]
35
    #[ORM\Column(length: 80)]
36
    #[Assert\Length(min: 1, max: 80)]
37
    private string $name;
38
39
    #[ORM\Column(type: Types::TEXT)]
40
    private $value;
41
42
    /**
43
     * non-persisted property
44
     */
45
    private string $extra;
46
47
    /**
48
     * @param mixed $value
49
     */
50
    public function __construct(User $user, string $name, $value)
51
    {
52
        $this->setUser($user)
53
            ->setAttribute($name, $value);
54
    }
55
56
    public function getUser(): User
57
    {
58
        return $this->user;
59
    }
60
61
    public function setUser(User $user): self
62
    {
63
        $this->user = $user;
64
65
        return $this;
66
    }
67
68
    public function getName(): string
69
    {
70
        return $this->name;
71
    }
72
73
    public function setName(string $name): self
74
    {
75
        $this->name = $name;
76
77
        return $this;
78
    }
79
80
    public function getValue()
81
    {
82
        return $this->value;
83
    }
84
85
    public function setValue(mixed $value): self
86
    {
87
        $this->value = $value;
88
89
        return $this;
90
    }
91
92
    public function setAttribute(string $name, mixed $value): self
93
    {
94
        $this->setName($name);
95
        $this->setValue($value);
96
97
        return $this;
98
    }
99
100
    public function getExtra(): string
101
    {
102
        return $this->extra;
103
    }
104
105
    public function setExtra(string $extra): self
106
    {
107
        $this->extra = $extra;
108
109
        return $this;
110
    }
111
112
    public function __toString(): string
113
    {
114
        return $this->getValue();
115
    }
116
}
117