ListElement   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 85
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 85
loc 85
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 4 4 1
A setSubtitle() 6 6 1
A setImageUrl() 6 6 1
A setDefaultAction() 6 6 1
A setButtons() 8 8 1
A toArray() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Kerox\Messenger\Model\Message\Attachment\Template\Element;
6
7
use Kerox\Messenger\Model\Common\Button\WebUrl;
8
9 View Code Duplication
class ListElement extends AbstractElement
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...
10
{
11
    /**
12
     * @var \Kerox\Messenger\Model\Common\Button\WebUrl
13
     */
14
    protected $defaultAction;
15
16
    /**
17
     * @var \Kerox\Messenger\Model\Common\Button\AbstractButton[]
18
     */
19
    protected $buttons = [];
20
21
    /**
22
     * @throws \Kerox\Messenger\Exception\MessengerException
23
     *
24
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement
25
     */
26 2
    public static function create(string $title): self
27
    {
28 2
        return new self($title);
29
    }
30
31
    /**
32
     * @throws \Kerox\Messenger\Exception\MessengerException
33
     *
34
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement
35
     */
36 2
    public function setSubtitle(string $subtitle): self
37
    {
38 2
        parent::setSubtitle($subtitle);
39
40 2
        return $this;
41
    }
42
43
    /**
44
     * @throws \Kerox\Messenger\Exception\MessengerException
45
     *
46
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement
47
     */
48 2
    public function setImageUrl(string $imageUrl): self
49
    {
50 2
        parent::setImageUrl($imageUrl);
51
52 2
        return $this;
53
    }
54
55
    /**
56
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement
57
     */
58 2
    public function setDefaultAction(WebUrl $defaultAction): self
59
    {
60 2
        $this->defaultAction = $defaultAction;
61
62 2
        return $this;
63
    }
64
65
    /**
66
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton[] $buttons
67
     *
68
     * @throws \Kerox\Messenger\Exception\MessengerException
69
     *
70
     * @return \Kerox\Messenger\Model\Message\Attachment\Template\Element\ListElement
71
     */
72 2
    public function setButtons(array $buttons): self
73
    {
74 2
        $this->isValidArray($buttons, 1);
75
76 2
        $this->buttons = $buttons;
77
78 2
        return $this;
79
    }
80
81 1
    public function toArray(): array
82
    {
83 1
        $array = parent::toArray();
84
        $array += [
85 1
            'subtitle' => $this->subtitle,
86 1
            'image_url' => $this->imageUrl,
87 1
            'default_action' => $this->defaultAction,
88 1
            'buttons' => $this->buttons,
89
        ];
90
91 1
        return array_filter($array);
92
    }
93
}
94