CategoryEntity   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 3 1
A toCategory() 0 5 1
A fromCategory() 0 5 1
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