createFromArticleTranslation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
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\Article;
5
6
use Yproximite\Api\Message\MessageInterface;
7
use Yproximite\Api\Message\LocaleAwareMessageTrait;
8
use Yproximite\Api\Model\Article\ArticleTranslation;
9
10
/**
11
 * Class ArticleTranslationMessage
12
 */
13 View Code Duplication
class ArticleTranslationMessage 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 LocaleAwareMessageTrait;
16
17
    /**
18
     * @var string
19
     */
20
    private $title = '';
21
22
    /**
23
     * @var string|null
24
     */
25
    private $body;
26
27
    /**
28
     * @param ArticleTranslation $translation
29
     *
30
     * @return self
31
     */
32
    public static function createFromArticleTranslation(ArticleTranslation $translation): self
33
    {
34
        $message = new self();
35
        $message->setLocale($translation->getLocale());
36
        $message->setTitle($translation->getTitle());
37
        $message->setBody($translation->getBody());
38
39
        return $message;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getTitle(): string
46
    {
47
        return $this->title;
48
    }
49
50
    /**
51
     * @param string $title
52
     */
53
    public function setTitle(string $title)
54
    {
55
        $this->title = $title;
56
    }
57
58
    /**
59
     * @return null|string
60
     */
61
    public function getBody()
62
    {
63
        return $this->body;
64
    }
65
66
    /**
67
     * @param null|string $body
68
     */
69
    public function setBody(string $body = null)
70
    {
71
        $this->body = $body;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function build()
78
    {
79
        return [
80
            'title' => $this->getTitle(),
81
            'body'  => $this->getBody(),
82
        ];
83
    }
84
}
85