Language::getCreatedValueObject()   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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the SexyField package.
5
 *
6
 * (c) Dion Snoeijen <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare (strict_types = 1);
13
14
namespace Tardigrades\Entity;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Tardigrades\SectionField\ValueObject\Created;
19
use Tardigrades\SectionField\ValueObject\I18n;
20
use Tardigrades\SectionField\ValueObject\Id;
21
use Tardigrades\SectionField\ValueObject\Updated;
22
23
class Language implements LanguageInterface
24
{
25
    /** @var int */
26
    protected $id;
27
28
    /** @var string */
29
    protected $i18n;
30
31
    /** @var ArrayCollection */
32
    protected $applications;
33
34
    /** @var \DateTime */
35
    protected $created;
36
37
    /** @var \DateTime */
38
    protected $updated;
39
40
    public function __construct(
41
        Collection $applications = null
42
    ) {
43
        $this->applications = is_null($applications) ? new ArrayCollection() : $applications;
44
    }
45
46
    public function setId(int $id): LanguageInterface
47
    {
48
        $this->id = $id;
49
50
        return $this;
51
    }
52
53
    public function getId(): ?int
54
    {
55
        return $this->id;
56
    }
57
58
    public function getIdValueObject(): Id
59
    {
60
        return Id::fromInt($this->id);
61
    }
62
63
    public function setI18n(string $i18n): LanguageInterface
64
    {
65
        $this->i18n = $i18n;
66
67
        return $this;
68
    }
69
70
    public function getI18n(): I18n
71
    {
72
        return I18n::fromString($this->i18n);
73
    }
74
75
    public function addApplication(ApplicationInterface $application): LanguageInterface
76
    {
77
        if ($this->applications->contains($application)) {
78
            return $this;
79
        }
80
        $this->applications->add($application);
81
82
        return $this;
83
    }
84
85
    public function getApplications(): ArrayCollection
86
    {
87
        return $this->applications;
88
    }
89
90
    public function removeApplication(ApplicationInterface $application): LanguageInterface
91
    {
92
        if (!$this->applications->contains($application)) {
93
            return $this;
94
        }
95
        $this->applications->removeElement($application);
96
97
        return $this;
98
    }
99
100
    public function setCreated(\DateTime $created): LanguageInterface
101
    {
102
        $this->created = $created;
103
104
        return $this;
105
    }
106
107
    public function getCreated(): \DateTime
108
    {
109
        return $this->created;
110
    }
111
112
    public function getCreatedValueObject(): Created
113
    {
114
        return Created::fromDateTime($this->created);
115
    }
116
117
    public function setUpdated(\DateTime $updated): LanguageInterface
118
    {
119
        $this->updated = $updated;
120
121
        return $this;
122
    }
123
124
    public function getUpdated(): \DateTime
125
    {
126
        return $this->updated;
127
    }
128
129
    public function getUpdatedValueObject(): Updated
130
    {
131
        return Updated::fromDateTime($this->updated);
132
    }
133
134
    public function onPrePersist(): void
135
    {
136
        $this->updated = new \DateTime('now');
137
        $this->created = new \DateTime('now');
138
    }
139
140
    public function onPreUpdate(): void
141
    {
142
        $this->updated = new \DateTime('now');
143
    }
144
}
145