Completed
Push — feature/VSVGVQ-7-Entities ( cc0453 )
by Luc
02:51
created

CategoryEntity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setName() 0 3 1
A getName() 0 3 1
A toCategory() 0 5 1
A fromCategory() 0 5 1
1
<?php
2
3
namespace VSV\GVQ_API\Question\Repositories\Entities;
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 extends Entity
15
{
16
    /**
17
     * @var string
18
     *
19
     * @ORM\Column(type="string", length=255, unique=true, nullable=false)
20
     */
21
    private $name;
22
23
    /**
24
     * @param string $id
25
     * @param string $name
26
     */
27
    private function __construct(
28
        string $id,
29
        string $name
30
    ) {
31
        parent::__construct($id);
32
        $this->name = $name;
33
    }
34
35
    /**
36
     * @param Category $category
37
     * @return CategoryEntity
38
     */
39
    public static function fromCategory(Category $category): CategoryEntity
40
    {
41
        return new CategoryEntity(
42
            $category->getId()->toString(),
43
            $category->getName()->toNative()
44
        );
45
    }
46
47
    /**
48
     * @return Category
49
     */
50
    public function toCategory(): Category
51
    {
52
        return new Category(
53
            Uuid::fromString($this->getId()),
54
            new NotEmptyString($this->getName())
55
        );
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getName(): string
62
    {
63
        return $this->name;
64
    }
65
66
    /**
67
     * @param string $name
68
     */
69
    public function setName(string $name): void
70
    {
71
        $this->name = $name;
72
    }
73
}
74