Passed
Pull Request — master (#59)
by
unknown
11:04
created

AbstractTranslation::getLocale()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Locastic\ApiPlatformTranslationBundle\Model;
6
7
/**
8
 * Class AbstractTranslation
9
 *
10
 * @package Locastic\ApiPlatformTranslationBundle\Model
11
 */
12
abstract class AbstractTranslation implements TranslationInterface
13
{
14
    protected ?TranslatableInterface $translatable = null;
15
16
    public function __construct(
17
        protected ?string $locale = null,
18
        ?TranslatableInterface $translatable = null
19
    ) {
20
        $this->setTranslatable($translatable);
21
    }
22
23
    /**
24
     * @codeCoverageIgnore
25
     */
26
    public function getTranslatable(): ?TranslatableInterface
27
    {
28
        return $this->translatable;
29
    }
30
31
    public function setTranslatable(?TranslatableInterface $translatable): void
32
    {
33
        if ($translatable === $this->translatable) {
34
            return;
35
        }
36
37
        $previousTranslatable = $this->translatable;
38
        $this->translatable = $translatable;
39
40
        $previousTranslatable?->removeTranslation($this);
41
42
        $translatable?->addTranslation($this);
43
    }
44
45
    /**
46
     * @codeCoverageIgnore
47
     */
48
    public function getLocale(): ?string
49
    {
50
        return $this->locale;
51
    }
52
53
    /**
54
     * @codeCoverageIgnore
55
     */
56
    public function setLocale(?string $locale): void
57
    {
58
        $this->locale = $locale;
59
    }
60
}
61