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

AbstractTranslation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 47
rs 10
c 2
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setLocale() 0 3 1
A __construct() 0 5 1
A getTranslatable() 0 3 1
A getLocale() 0 3 1
A setTranslatable() 0 12 2
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