VatNumberAwareTrait::setVatNumber()   A
last analyzed

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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewebe\SyliusVATPlugin\Entity;
6
7
use DateTime;
8
use Doctrine\DBAL\Types\Types;
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Mapping\Annotation as Gedmo;
11
use Symfony\Component\Serializer\Annotation\Groups;
12
13
/**
14
 * Trait that implements the vat number functionality
15
 * Used in:
16
 * <li>@see Address</li>
17
 */
18
trait VatNumberAwareTrait
19
{
20
    /**
21
     * @ORM\Column(name="vat_number", type="string", nullable=true)
22
     *
23
     * @Gedmo\Versioned()
24
     *
25
     * @Groups({"shop:address:read", "shop:address:create", "shop:address:update"})
26
     */
27
    #[ORM\Column(name: 'vat_number', type: Types::STRING, nullable: true)]
28
    #[Gedmo\Versioned()]
29
    #[Groups(['shop:address:read', 'shop:address:create', 'shop:address:update'])]
30
    protected ?string $vatNumber = null;
31
32
    /**
33
     * @ORM\Column(name="vat_valid", type="boolean")
34
     *
35
     * @Groups({"shop:address:read"})
36
     */
37
    #[ORM\Column(name: 'vat_valid', type: Types::BOOLEAN)]
38
    #[Groups(['shop:address:read'])]
39
    protected bool $vatValid = false;
40
41
    /**
42
     * @ORM\Column(name="vat_validated_at", type="datetime", nullable=true)
43
     *
44
     * @Groups({"shop:address:read"})
45
     */
46
    #[ORM\Column(name: 'vat_validated_at', type: Types::DATETIME_MUTABLE, nullable: true)]
47
    #[Groups(['shop:address:read'])]
48
    protected ?DateTime $vatValidatedAt = null;
49
50
    public function getVatNumber(): ?string
51
    {
52
        return $this->vatNumber;
53
    }
54
55
    public function setVatNumber(?string $vatNumber): void
56
    {
57
        $this->vatNumber = $vatNumber;
58
    }
59
60
    public function hasVatNumber(): bool
61
    {
62
        return is_string($this->vatNumber) && strlen($this->vatNumber) > 0;
63
    }
64
65
    public function hasValidVatNumber(): bool
66
    {
67
        return $this->hasVatNumber() && $this->vatValid === true;
68
    }
69
70
    public function setVatValid(bool $valid, ?DateTime $validatedAt = null): void
71
    {
72
        $this->vatValid = $valid;
73
        $this->vatValidatedAt = $validatedAt ?? new DateTime();
74
    }
75
76
    public function getVatValidatedAt(): ?DateTime
77
    {
78
        return $this->vatValidatedAt;
79
    }
80
}
81