Nested::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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