Completed
Pull Request — master (#47)
by Romain
02:37
created

Menu::isValidButton()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
crap 3
1
<?php
2
namespace Kerox\Messenger\Model\ThreadSettings;
3
4
use Kerox\Messenger\Model\Common\Buttons\AbstractButtons;
5
use Kerox\Messenger\Model\ThreadSettings;
6
7
/**
8
 * @deprecated since 1.2.0 and will be remove in 1.3.0.
9
 * @see \Kerox\Messenger\Model\ProfileSettings\PersistentMenu
10
 */
11
class Menu extends ThreadSettings
0 ignored issues
show
Deprecated Code introduced by
The class Kerox\Messenger\Model\ThreadSettings has been deprecated with message: since 1.2.0 and will be remove in 1.3.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...
12
{
13
14
    /**
15
     * @var \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[]
16
     */
17
    protected $buttons;
18
19
    /**
20
     * Menu constructor.
21
     *
22
     * @param \Kerox\Messenger\Model\Common\Buttons\AbstractButtons[] $buttons
23
     */
24 1
    public function __construct(array $buttons)
25
    {
26 1
        parent::__construct(ThreadSettings::TYPE_CALL_TO_ACTIONS, ThreadSettings::STATE_EXISTING_THREAD);
27
28 1
        $this->isValidArray($buttons, 5);
29 1
        $this->isValidButtons($buttons, $this->getAllowedButtonsType());
30
31 1
        $this->buttons = $buttons;
32 1
    }
33
34
    /**
35
     * @return array
36
     */
37 1
    protected function getAllowedButtonsType(): array
38
    {
39
        return [
40 1
            AbstractButtons::TYPE_WEB_URL,
41 1
            AbstractButtons::TYPE_POSTBACK,
42
        ];
43
    }
44
45
    /**
46
     * @return array
47
     */
48 1
    public function jsonSerialize(): array
49
    {
50 1
        $json = parent::jsonSerialize();
51
        $json += [
52 1
            'call_to_actions' => $this->buttons,
53
        ];
54
55 1
        return $json;
56
    }
57
}
58