AffiliateReferral::getAffiliate()   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 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusReferralsPlugin\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Sylius\Component\Core\Model\ProductInterface;
10
use Sylius\Component\Resource\Model\TimestampableTrait;
11
12
class AffiliateReferral implements AffiliateReferralInterface
13
{
14
    use TimestampableTrait;
15
16
    protected ?int $id = null;
17
18
    protected ?string $tokenValue = null;
19
20
    protected ?string $rewardType = null;
21
22
    protected ?\DateTimeInterface $expiresAt = null;
23
24
    protected ?AffiliateInterface $affiliate = null;
25
26
    protected ?ProductInterface $product = null;
27
28
    /** @psalm-var Collection<array-key, AffiliateReferralViewInterface> */
29
    protected Collection $views;
30
31
    public function __construct()
32
    {
33
        $this->views = new ArrayCollection();
34
        $this->createdAt = new \DateTime();
35
    }
36
37
    public function getId(): ?int
38
    {
39
        return $this->id;
40
    }
41
42
    public function getTokenValue(): ?string
43
    {
44
        return $this->tokenValue;
45
    }
46
47
    public function setTokenValue(?string $tokenValue): void
48
    {
49
        $this->tokenValue = $tokenValue;
50
    }
51
52
    public function getRewardType(): ?string
53
    {
54
        return $this->rewardType;
55
    }
56
57
    public function setRewardType(?string $rewardType): void
58
    {
59
        $this->rewardType = $rewardType;
60
    }
61
62
    public function getExpiresAt(): ?\DateTimeInterface
63
    {
64
        return $this->expiresAt;
65
    }
66
67
    public function setExpiresAt(?\DateTimeInterface $expiresAt): void
68
    {
69
        $this->expiresAt = $expiresAt;
70
    }
71
72
    public function isExpired(): bool
73
    {
74
        if ($this->expiresAt === null) {
75
            return false;
76
        }
77
78
        $now = new \DateTime();
79
80
        return $now > $this->expiresAt;
81
    }
82
83
    public function getAffiliate(): ?AffiliateInterface
84
    {
85
        return $this->affiliate;
86
    }
87
88
    public function setAffiliate(?AffiliateInterface $affiliate): void
89
    {
90
        $this->affiliate = $affiliate;
91
    }
92
93
    public function getProduct(): ?ProductInterface
94
    {
95
        return $this->product;
96
    }
97
98
    public function setProduct(?ProductInterface $product): void
99
    {
100
        $this->product = $product;
101
    }
102
103
    public function getViews(): Collection
104
    {
105
        return $this->views;
106
    }
107
108
    public function hasView(AffiliateReferralViewInterface $view): bool
109
    {
110
        return $this->views->contains($view);
111
    }
112
113
    public function addView(AffiliateReferralViewInterface $view): void
114
    {
115
        if (!$this->hasView($view)) {
116
            $this->views->add($view);
117
            $view->setAffiliateReferral($this);
118
        }
119
    }
120
121
    public function removeView(AffiliateReferralViewInterface $view): void
122
    {
123
        if ($this->hasView($view)) {
124
            $this->views->removeElement($view);
125
            $view->setAffiliateReferral(null);
126
        }
127
    }
128
}
129