Passed
Push — feature/VSVGVQ-7 ( 05f4d2...f0f3aa )
by Luc
02:30
created

CategoryEntity::getName()   A

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 declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Question\Repositories;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Ramsey\Uuid\Uuid;
7
use VSV\GVQ_API\Question\Models\Category;
8
use VSV\GVQ_API\Question\ValueObjects\NotEmptyString;
9
10
/**
11
 * @ORM\Entity
12
 * @ORM\Table(name="category")
13
 */
14
class CategoryEntity
15
{
16
    /**
17
     * @var string
18
     *
19
     * @ORM\Id
20
     * @ORM\Column(type="guid")
21
     */
22
    private $id;
23
24
    /**
25
     * @var string
26
     *
27
     * @ORM\Column(type="string")
28
     */
29
    private $name;
30
31
    /**
32
     * @param string $id
33
     * @param string $name
34
     */
35
    public function __construct(
36
        string $id,
37
        string $name
38
    ) {
39
        $this->id = $id;
40
        $this->name = $name;
41
    }
42
43
    /**
44
     * @param Category $category
45
     * @return CategoryEntity
46
     */
47
    public static function fromCategory(Category $category)
48
    {
49
        return new self(
50
            $category->getId()->toString(),
51
            $category->getName()->toNative()
52
        );
53
    }
54
55
    /**
56
     * @return Category
57
     */
58
    public function toCategory()
59
    {
60
        return new Category(
61
            Uuid::fromString($this->id),
62
            new NotEmptyString($this->name)
63
        );
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getId(): string
70
    {
71
        return $this->id;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getName(): string
78
    {
79
        return $this->name;
80
    }
81
}
82