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

Menu   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 47
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getAllowedButtonsType() 0 7 1
A jsonSerialize() 0 9 1
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