Completed
Push — master ( c99558...2132f5 )
by Peter
05:41
created

Country::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
namespace AnimeDb\Bundle\CatalogBundle\Entity;
10
11
use Doctrine\ORM\Mapping as ORM;
12
use Symfony\Component\Validator\Constraints as Assert;
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Gedmo\Mapping\Annotation as Gedmo;
15
use Gedmo\Translatable\Translatable;
16
17
/**
18
 * Country.
19
 *
20
 * @ORM\Entity
21
 * @ORM\Table(name="country")
22
 * @Gedmo\TranslationEntity(class="AnimeDb\Bundle\CatalogBundle\Entity\CountryTranslation")
23
 *
24
 * @author  Peter Gribanov <[email protected]>
25
 */
26
class Country implements Translatable
27
{
28
    /**
29
     * @ORM\Id
30
     * @ORM\Column(type="string", length=2)
31
     * @Assert\NotBlank()
32
     * @Assert\Country()
33
     *
34
     * @var string
35
     */
36
    protected $id = 0;
37
38
    /**
39
     * @ORM\Column(type="string", length=16)
40
     * @Assert\NotBlank()
41
     * @Gedmo\Translatable
42
     *
43
     * @var string
44
     */
45
    protected $name = '';
46
47
    /**
48
     * @ORM\OneToMany(targetEntity="Item", mappedBy="country")
49
     *
50
     * @var ArrayCollection
51
     */
52
    protected $items;
53
54
    /**
55
     * Entity locale.
56
     *
57
     * @Gedmo\Locale
58
     *
59
     * @var string
60
     */
61
    protected $locale = '';
62
63
    /**
64
     * @ORM\OneToMany(
65
     *     targetEntity="CountryTranslation",
66
     *     mappedBy="object",
67
     *     cascade={"persist", "remove"}
68
     * )
69
     */
70
    protected $translations;
71
72 87
    public function __construct()
73
    {
74 87
        $this->items = new ArrayCollection();
75 87
        $this->translations = new ArrayCollection();
76 87
    }
77
78
    /**
79
     * @param string $id
80
     *
81
     * @return Country
82
     */
83 1
    public function setId($id)
84
    {
85 1
        $this->id = $id;
86
87 1
        return $this;
88
    }
89
90
    /**
91
     * @return string
92
     */
93 1
    public function getId()
94
    {
95 1
        return $this->id;
96
    }
97
98
    /**
99
     * @param string $name
100
     *
101
     * @return Country
102
     */
103 2
    public function setName($name)
104
    {
105 2
        $this->name = $name;
106
107 2
        return $this;
108
    }
109
110
    /**
111
     * @return string
112
     */
113 2
    public function getName()
114
    {
115 2
        return $this->name;
116
    }
117
118
    /**
119
     * @param Item $item
120
     *
121
     * @return Country
122
     */
123 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...
124
    {
125 1
        if (!$this->items->contains($item)) {
126 1
            $this->items->add($item);
127 1
            $item->setCountry($this);
128 1
        }
129
130 1
        return $this;
131
    }
132
133
    /**
134
     * @param Item $item
135
     *
136
     * @return Country
137
     */
138 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...
139
    {
140 1
        if ($this->items->contains($item)) {
141 1
            $this->items->removeElement($item);
142 1
            $item->setCountry(null);
143 1
        }
144
145 1
        return $this;
146
    }
147
148
    /**
149
     * @return ArrayCollection
150
     */
151 1
    public function getItems()
152
    {
153 1
        return $this->items;
154
    }
155
156
    /**
157
     * @param string $locale
158
     *
159
     * @return Country
160
     */
161 1
    public function setTranslatableLocale($locale)
162
    {
163 1
        $this->locale = $locale;
164
165 1
        return $this;
166
    }
167
168
    /**
169
     * @return string
170
     */
171 1
    public function getTranslatableLocale()
172
    {
173 1
        return $this->locale;
174
    }
175
176
    /**
177
     * @return ArrayCollection
178
     */
179 1
    public function getTranslations()
180
    {
181 1
        return $this->translations;
182
    }
183
184
    /**
185
     * @param CountryTranslation $trans
186
     *
187
     * @return Country
188
     */
189 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...
190
    {
191 1
        if (!$this->translations->contains($trans)) {
192 1
            $this->translations->add($trans);
193 1
            $trans->setObject($this);
194 1
        }
195
196 1
        return $this;
197
    }
198
199
    /**
200
     * @param CountryTranslation $trans
201
     *
202
     * @return Country
203
     */
204 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...
205
    {
206 1
        if ($this->translations->contains($trans)) {
207 1
            $this->translations->removeElement($trans);
208 1
            $trans->setObject(null);
209 1
        }
210
211 1
        return $this;
212
    }
213
214
    /**
215
     * @return string
216
     */
217 1
    public function __toString()
218
    {
219 1
        return $this->getName();
220
    }
221
}
222