Completed
Push — master ( 9af059...286024 )
by Luc
12s
created

TranslatedAliasEntity::setCompanyEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\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\Common\ValueObjects\Language;
9
use VSV\GVQ_API\Company\Models\TranslatedAlias;
10
use VSV\GVQ_API\Company\ValueObjects\Alias;
11
12
/**
13
 * @ORM\Entity()
14
 * @ORM\Table(name="translated_alias")
15
 */
16
class TranslatedAliasEntity extends Entity
17
{
18
    /**
19
     * @var string
20
     * @ORM\Column(type="string", length=255, unique=true, nullable=false)
21
     */
22
    private $alias;
23
24
    /**
25
     * @var string
26
     * @ORM\Column(type="string", length=2, nullable=false)
27
     */
28
    private $language;
29
30
    /**
31
     * @var CompanyEntity
32
     * @ORM\ManyToOne(targetEntity="CompanyEntity", inversedBy="translatedAliasEntities")
33
     * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=false)
34
     */
35
    private $companyEntity;
36
37
    /**
38
     * @param string $id
39
     * @param string $language
40
     * @param string $alias
41
     */
42
    public function __construct(
43
        string $id,
44
        string $language,
45
        string $alias
46
    ) {
47
        parent::__construct($id);
48
49
        $this->language = $language;
50
        $this->alias = $alias;
51
    }
52
53
    /**
54
     * @param TranslatedAlias $translatedAlias
55
     * @return TranslatedAliasEntity
56
     */
57
    public static function fromTranslatedAlias(TranslatedAlias $translatedAlias): TranslatedAliasEntity
58
    {
59
        return new TranslatedAliasEntity(
60
            $translatedAlias->getId()->toString(),
61
            $translatedAlias->getLanguage()->toNative(),
62
            $translatedAlias->getAlias()->toNative()
63
        );
64
    }
65
66
    /**
67
     * @return TranslatedAlias
68
     */
69
    public function toTranslatedAlias(): TranslatedAlias
70
    {
71
        return new TranslatedAlias(
72
            Uuid::fromString($this->getId()),
73
            new Language($this->getLanguage()),
74
            new Alias($this->getAlias())
75
        );
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getAlias(): string
82
    {
83
        return $this->alias;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getLanguage(): string
90
    {
91
        return $this->language;
92
    }
93
94
    /**
95
     * @param CompanyEntity $companyEntity
96
     */
97
    public function setCompanyEntity(CompanyEntity $companyEntity): void
98
    {
99
        $this->companyEntity = $companyEntity;
100
    }
101
}
102