Country::setId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\Entity;
11
12
use Doctrine\ORM\Mapping as ORM;
13
use Symfony\Component\Validator\Constraints as Assert;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Gedmo\Mapping\Annotation as Gedmo;
16
use Gedmo\Translatable\Translatable;
17
18
/**
19
 * Country.
20
 *
21
 * @ORM\Entity
22
 * @ORM\Table(name="country")
23
 * @Gedmo\TranslationEntity(class="AnimeDb\Bundle\CatalogBundle\Entity\CountryTranslation")
24
 *
25
 * @author  Peter Gribanov <[email protected]>
26
 */
27
class Country implements Translatable
28
{
29
    /**
30
     * @ORM\Id
31
     * @ORM\Column(type="string", length=2)
32
     * @Assert\NotBlank()
33
     * @Assert\Country()
34
     *
35
     * @var string
36
     */
37
    protected $id = 0;
38
39
    /**
40
     * @ORM\Column(type="string", length=16)
41
     * @Assert\NotBlank()
42
     * @Gedmo\Translatable
43
     *
44
     * @var string
45
     */
46
    protected $name = '';
47
48
    /**
49
     * @ORM\OneToMany(targetEntity="Item", mappedBy="country")
50
     *
51
     * @var ArrayCollection
52
     */
53
    protected $items;
54
55
    /**
56
     * Entity locale.
57
     *
58
     * @Gedmo\Locale
59
     *
60
     * @var string
61
     */
62
    protected $locale = '';
63
64
    /**
65
     * @ORM\OneToMany(
66
     *     targetEntity="CountryTranslation",
67
     *     mappedBy="object",
68
     *     cascade={"persist", "remove"}
69
     * )
70
     */
71
    protected $translations;
72
73 87
    public function __construct()
74
    {
75 87
        $this->items = new ArrayCollection();
76 87
        $this->translations = new ArrayCollection();
77 87
    }
78
79
    /**
80
     * @param string $id
81
     *
82
     * @return Country
83
     */
84 1
    public function setId($id)
85
    {
86 1
        $this->id = $id;
87
88 1
        return $this;
89
    }
90
91
    /**
92
     * @return string
93
     */
94 1
    public function getId()
95
    {
96 1
        return $this->id;
97
    }
98
99
    /**
100
     * @param string $name
101
     *
102
     * @return Country
103
     */
104 2
    public function setName($name)
105
    {
106 2
        $this->name = $name;
107
108 2
        return $this;
109
    }
110
111
    /**
112
     * @return string
113
     */
114 2
    public function getName()
115
    {
116 2
        return $this->name;
117
    }
118
119
    /**
120
     * @param Item $item
121
     *
122
     * @return Country
123
     */
124 1 View Code Duplication
    public function addItem(Item $item)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126 1
        if (!$this->items->contains($item)) {
127 1
            $this->items->add($item);
128 1
            $item->setCountry($this);
129 1
        }
130
131 1
        return $this;
132
    }
133
134
    /**
135
     * @param Item $item
136
     *
137
     * @return Country
138
     */
139 1 View Code Duplication
    public function removeItem(Item $item)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
140
    {
141 1
        if ($this->items->contains($item)) {
142 1
            $this->items->removeElement($item);
143 1
            $item->setCountry(null);
144 1
        }
145
146 1
        return $this;
147
    }
148
149
    /**
150
     * @return ArrayCollection
151
     */
152 1
    public function getItems()
153
    {
154 1
        return $this->items;
155
    }
156
157
    /**
158
     * @param string $locale
159
     *
160
     * @return Country
161
     */
162 1
    public function setTranslatableLocale($locale)
163
    {
164 1
        $this->locale = $locale;
165
166 1
        return $this;
167
    }
168
169
    /**
170
     * @return string
171
     */
172 1
    public function getTranslatableLocale()
173
    {
174 1
        return $this->locale;
175
    }
176
177
    /**
178
     * @return ArrayCollection
179
     */
180 1
    public function getTranslations()
181
    {
182 1
        return $this->translations;
183
    }
184
185
    /**
186
     * @param CountryTranslation $trans
187
     *
188
     * @return Country
189
     */
190 1 View Code Duplication
    public function addTranslation(CountryTranslation $trans)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191
    {
192 1
        if (!$this->translations->contains($trans)) {
193 1
            $this->translations->add($trans);
194 1
            $trans->setObject($this);
195 1
        }
196
197 1
        return $this;
198
    }
199
200
    /**
201
     * @param CountryTranslation $trans
202
     *
203
     * @return Country
204
     */
205 1 View Code Duplication
    public function removeTranslation(CountryTranslation $trans)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
206
    {
207 1
        if ($this->translations->contains($trans)) {
208 1
            $this->translations->removeElement($trans);
209 1
            $trans->setObject(null);
210 1
        }
211
212 1
        return $this;
213
    }
214
215
    /**
216
     * @return string
217
     */
218 1
    public function __toString()
219
    {
220 1
        return $this->getName();
221
    }
222
}
223