Nested   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 11
loc 77
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 1
A create() 0 4 1
A addButton() 0 8 1
A getAllowedButtonsType() 0 8 1
A toArray() 0 10 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\Common\Button;
6
7
/**
8
 * @deprecated Since version 3.2.0 and will be removed in version 4.0.0.
9
 */
10
class Nested extends AbstractButton
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $title;
16
17
    /**
18
     * @var \Kerox\Messenger\Model\Common\Button\AbstractButton[]
19
     */
20
    protected $buttons;
21
22
    /**
23
     * Nested constructor.
24
     *
25
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton[] $buttons
26
     *
27
     * @throws \Kerox\Messenger\Exception\MessengerException
28
     */
29 3 View Code Duplication
    public function __construct(string $title, array $buttons)
0 ignored issues
show
Duplication introduced by
This method 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...
30
    {
31 3
        parent::__construct(self::TYPE_NESTED);
0 ignored issues
show
Deprecated Code introduced by
The constant Kerox\Messenger\Model\Co...ractButton::TYPE_NESTED has been deprecated with message: Since version 3.3.1 and will be removed in version 4.0.0.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
32
33 3
        $this->isValidString($title, 20);
34 3
        $this->isValidArray($buttons, 5);
35 3
        $this->isValidButtons($buttons, $this->getAllowedButtonsType());
36
37 3
        $this->title = $title;
38 3
        $this->buttons = $buttons;
39 3
    }
40
41
    /**
42
     * @throws \Kerox\Messenger\Exception\MessengerException
43
     *
44
     * @return \Kerox\Messenger\Model\Common\Button\Nested
45
     */
46 3
    public static function create(string $title, array $buttons): self
47
    {
48 3
        return new self($title, $buttons);
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Model\Common\Button\Nested has been deprecated with message: Since version 3.2.0 and will be removed in version 4.0.0.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
49
    }
50
51
    /**
52
     * @param \Kerox\Messenger\Model\Common\Button\AbstractButton $button
53
     *
54
     * @throws \Kerox\Messenger\Exception\MessengerException
55
     *
56
     * @return \Kerox\Messenger\Model\Common\Button\Nested
57
     */
58 1
    public function addButton(AbstractButton $button): self
59
    {
60 1
        $this->isValidButtons([$button], $this->getAllowedButtonsType());
61
62 1
        $this->buttons[] = $button;
63
64 1
        return $this;
65
    }
66
67 3
    protected function getAllowedButtonsType(): array
68
    {
69
        return [
70 3
            AbstractButton::TYPE_WEB_URL,
71
            AbstractButton::TYPE_POSTBACK,
72
            AbstractButton::TYPE_NESTED,
0 ignored issues
show
Deprecated Code introduced by
The constant Kerox\Messenger\Model\Co...ractButton::TYPE_NESTED has been deprecated with message: Since version 3.3.1 and will be removed in version 4.0.0.

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
73
        ];
74
    }
75
76 2
    public function toArray(): array
77
    {
78 2
        $array = parent::toArray();
79
        $array += [
80 2
            'title' => $this->title,
81 2
            'call_to_actions' => $this->buttons,
82
        ];
83
84 2
        return $array;
85
    }
86
}
87