CategoryEntity::toCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
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\Common\Repositories\Entities\Entity;
8
use VSV\GVQ_API\Question\Models\Category;
9
use VSV\GVQ_API\Common\ValueObjects\NotEmptyString;
10
11
/**
12
 * @ORM\Entity()
13
 * @ORM\Table(name="category")
14
 */
15
class CategoryEntity extends Entity
16
{
17
    /**
18
     * @var string
19
     *
20
     * @ORM\Column(type="string", length=255, unique=true, nullable=false)
21
     */
22
    private $name;
23
24
    /**
25
     * @param string $id
26
     * @param string $name
27
     */
28
    private function __construct(
29
        string $id,
30
        string $name
31
    ) {
32
        parent::__construct($id);
33
        $this->name = $name;
34
    }
35
36
    /**
37
     * @param Category $category
38
     * @return CategoryEntity
39
     */
40
    public static function fromCategory(Category $category): CategoryEntity
41
    {
42
        return new CategoryEntity(
43
            $category->getId()->toString(),
44
            $category->getName()->toNative()
45
        );
46
    }
47
48
    /**
49
     * @return Category
50
     */
51
    public function toCategory(): Category
52
    {
53
        return new Category(
54
            Uuid::fromString($this->getId()),
55
            new NotEmptyString($this->getName())
56
        );
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getName(): string
63
    {
64
        return $this->name;
65
    }
66
}
67