Passed
Push — main ( b87b9b...32046f )
by Axel
04:33
created

UserAttribute::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
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\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)]
25
#[ORM\Table(name: 'users_attributes')]
26
class UserAttribute
27
{
28
    #[ORM\Id]
29
    #[ORM\ManyToOne(inversedBy: 'attributes')]
30
    #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'uid', onDelete: 'CASCADE')]
31
    private User $user;
32
33
    #[ORM\Id]
34
    #[ORM\Column(length: 80)]
35
    #[Assert\Length(min: 1, max: 80)]
36
    private string $name;
37
38
    #[ORM\Column(type: Types::TEXT)]
39
    private $value;
40
41
    /**
42
     * non-persisted property
43
     */
44
    private string $extra;
45
46
    /**
47
     * @param mixed $value
48
     */
49
    public function __construct(User $user, string $name, $value)
50
    {
51
        $this->setUser($user);
52
        $this->setAttribute($name, $value);
53
    }
54
55
    public function getUser(): User
56
    {
57
        return $this->user;
58
    }
59
60
    public function setUser(User $user): self
61
    {
62
        $this->user = $user;
63
64
        return $this;
65
    }
66
67
    public function getName(): string
68
    {
69
        return $this->name;
70
    }
71
72
    public function setName(string $name): self
73
    {
74
        $this->name = $name;
75
76
        return $this;
77
    }
78
79
    public function getValue()
80
    {
81
        return $this->value;
82
    }
83
84
    public function setValue(mixed $value): self
85
    {
86
        $this->value = $value;
87
88
        return $this;
89
    }
90
91
    public function setAttribute(string $name, mixed $value): self
92
    {
93
        $this->setName($name);
94
        $this->setValue($value);
95
96
        return $this;
97
    }
98
99
    public function getExtra(): string
100
    {
101
        return $this->extra;
102
    }
103
104
    public function setExtra(string $extra): self
105
    {
106
        $this->extra = $extra;
107
108
        return $this;
109
    }
110
111
    public function __toString(): string
112
    {
113
        return $this->getValue();
114
    }
115
}
116