Country::getCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Countries\Entity;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
use Symfony\Component\Serializer\Annotation\Groups;
10
11
/**
12
 * @ORM\Entity(repositoryClass="App\Countries\Repository\CountryRepository")
13
 * @ORM\Table(name="countries")
14
 * @UniqueEntity(fields="code", message="This code already exists")
15
 */
16
class Country
17
{
18
    /**
19
     * @ORM\Id()
20
     * @ORM\GeneratedValue()
21
     * @ORM\Column(type="integer")
22
     */
23
    private $id;
24
25
    /**
26
     * @ORM\Column(type="string", length=3, unique=true)
27
     * @Groups({"list", "view"})
28
     */
29
    private $code;
30
31
    /**
32
     * @ORM\Column(type="string", length=50, unique=true)
33
     * @Groups({"list", "view"})
34
     */
35
    private $name;
36
37
    public function __construct(string $name, string $code)
38
    {
39
        // todo movie to db constraint
40
        if (mb_strlen($code) !== 3) {
41
            // throw new \InvalidArgumentException(sprintf('"%s" should be exactly 3 characters long', $code));
42
        }
43
44
        $this->code = mb_strtoupper($code);
45
        $this->name = ucfirst($name);
46
    }
47
48
    public function getId()
49
    {
50
        return $this->id;
51
    }
52
53
    public function getCode(): string
54
    {
55
        return $this->code;
56
    }
57
58
    public function getName(): string
59
    {
60
        return $this->name;
61
    }
62
}
63