Alias::getDomain()   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
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * This file is part of the mailserver-admin package.
6
 * (c) Jeffrey Boehm <https://github.com/jeboehm/mailserver-admin>
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace App\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * @ORM\Entity(repositoryClass="App\Repository\AliasRepository")
19
 * @ORM\Table(name="mail_aliases", uniqueConstraints={@ORM\UniqueConstraint(name="alias_idx", columns={"domain_id", "name", "destination"})})
20
 * @UniqueEntity(fields={"destination", "name", "domain"})
21
 */
22
class Alias
23
{
24
    /**
25
     * @ORM\Id()
26
     * @ORM\GeneratedValue()
27
     * @ORM\Column(type="integer")
28
     */
29
    private ?int $id = null;
30
31
    /**
32
     * @ORM\ManyToOne(targetEntity="Domain", inversedBy="aliases")
33
     * @Assert\NotNull()
34
     */
35
    private ?Domain $domain = null;
36
37
    /**
38
     * @ORM\Column(type="string", name="name", options={"collation":"utf8_unicode_ci"})
39
     * @Assert\NotBlank()
40
     * @Assert\Regex(pattern="/^[a-z0-9\-\_.]{1,50}$/")
41
     */
42
    private string $name = '';
43
44
    /**
45
     * @ORM\Column(type="string", name="destination", options={"collation":"utf8_unicode_ci"})
46
     * @Assert\NotBlank()
47
     * @Assert\Email()
48
     */
49
    private string $destination = '';
50
51
    public function __toString(): string
52
    {
53
        if (null !== $this->getDomain()) {
54
            return sprintf('%s@%s → %s', $this->name, $this->getDomain()->getName(), $this->destination);
55
        }
56
57
        return '';
58
    }
59
60
    public function getDomain(): ?Domain
61
    {
62
        return $this->domain;
63
    }
64
65
    public function setDomain(Domain $domain): void
66
    {
67
        $this->domain = $domain;
68
    }
69
70
    public function getId(): ?int
71
    {
72
        return $this->id;
73
    }
74
75
    public function getName(): string
76
    {
77
        return $this->name;
78
    }
79
80
    public function setName(string $name): void
81
    {
82
        $this->name = $name;
83
    }
84
85
    public function getDestination(): string
86
    {
87
        return $this->destination;
88
    }
89
90
    public function setDestination(string $destination): void
91
    {
92
        $this->destination = $destination;
93
    }
94
}
95