AbstractFieldMessage::removeTranslation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Yproximite\Api\Message\Field;
5
6
use Yproximite\Api\Util\Helper;
7
use Yproximite\Api\Message\MessageInterface;
8
use Yproximite\Api\Message\SiteAwareMessageTrait;
9
10
/**
11
 * Class AbstractFieldMessage
12
 */
13 View Code Duplication
abstract class AbstractFieldMessage implements MessageInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    use SiteAwareMessageTrait;
16
17
    /**
18
     * @var string
19
     */
20
    private $token;
21
22
    /**
23
     * @var string
24
     */
25
    private $description;
26
27
    /**
28
     * @var FieldTranslationMessage[]
29
     */
30
    private $translations = [];
31
32
    /**
33
     * @return string
34
     */
35
    public function getToken(): string
36
    {
37
        return $this->token;
38
    }
39
40
    /**
41
     * @param string $token
42
     */
43
    public function setToken(string $token)
44
    {
45
        $this->token = $token;
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getDescription(): string
52
    {
53
        return $this->description;
54
    }
55
56
    /**
57
     * @param string $description
58
     */
59
    public function setDescription(string $description)
60
    {
61
        $this->description = $description;
62
    }
63
64
    /**
65
     * @return FieldTranslationMessage[]
66
     */
67
    public function getTranslations(): array
68
    {
69
        return $this->translations;
70
    }
71
72
    /**
73
     * @param FieldTranslationMessage $translation
74
     */
75
    public function addTranslation(FieldTranslationMessage $translation)
76
    {
77
        $this->translations[] = $translation;
78
    }
79
80
    /**
81
     * @param FieldTranslationMessage $translation
82
     */
83
    public function removeTranslation(FieldTranslationMessage $translation)
84
    {
85
        array_splice($this->translations, array_search($translation, $this->translations), 1);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function build()
92
    {
93
        return [
94
            'token'        => $this->getToken(),
95
            'description'  => $this->getDescription(),
96
            'translations' => Helper::buildMessages($this->getTranslations(), 'locale'),
97
        ];
98
    }
99
}
100