GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ElementList::__construct()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.2269

Importance

Changes 0
Metric Value
dl 0
loc 20
c 0
b 0
f 0
ccs 10
cts 12
cp 0.8333
rs 8.2222
cc 7
eloc 11
nc 4
nop 3
crap 7.2269
1
<?php
2
3
namespace Tgallice\FBMessenger\Model\Attachment\Template;
4
5
use Tgallice\FBMessenger\Model\Attachment\Template;
6
use Tgallice\FBMessenger\Model\Attachment\Template\ElementList\Element;
7
use Tgallice\FBMessenger\Model\Button as ButtonModel;
8
9
class ElementList extends Template
10
{
11
    const TOP_STYLE_COMPACT = 'compact';
12
    const TOP_STYLE_LARGE = 'large';
13
14
    /**
15
     * @var Element[]
16
     */
17
    private $elements;
18
19
    /**
20
     * @var ButtonModel|null
21
     */
22
    private $button;
23
24
    /**
25
     * @var string
26
     */
27
    private $topElementStyle;
28
29
    /**
30
     * @param Element[] $elements
31
     * @param ButtonModel|null $button
32
     * @param string $topElementStyle
33
     */
34 11
    public function __construct(array $elements, ButtonModel $button = null, $topElementStyle = self::TOP_STYLE_LARGE)
35
    {
36 11
        if (empty($elements) || (count($elements) < 2 || count($elements) > 4)) {
37 3
            throw new \InvalidArgumentException('You must provide between 2 and 4 elements.');
38
        }
39
40 8
        $topElementStyle = strtolower($topElementStyle);
41
42 8
        if (!in_array($topElementStyle, [self::TOP_STYLE_LARGE, self::TOP_STYLE_COMPACT])) {
43
            throw new \InvalidArgumentException(sprintf('"%s" is not a valid top element style.', $topElementStyle));
44
        }
45
46 8
        if ($topElementStyle === self::TOP_STYLE_LARGE && empty($elements[0]->getImageUrl())) {
47
            throw new \InvalidArgumentException(sprintf('If the top element style is "%s" your first element must have an image url', self::TOP_STYLE_LARGE));
48
        }
49
50 8
        $this->elements = $elements;
51 8
        $this->button = $button;
52 8
        $this->topElementStyle = $topElementStyle;
53 8
    }
54
55
    /**
56
     * @return Element[]
57
     */
58 1
    public function getElements()
59
    {
60 1
        return $this->elements;
61
    }
62
63
    /**
64
     * @return string
65
     */
66 2
    public function getTopElementStyle()
67
    {
68 2
        return $this->topElementStyle;
69
    }
70
71
    /**
72
     * @return null|ButtonModel
73
     */
74 1
    public function getButton()
75
    {
76 1
        return $this->button;
77
    }
78
79
    /**
80
     * @return string
81
     */
82 2
    public function getType()
83
    {
84 2
        return Template::TYPE_LIST;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 1
    public function jsonSerialize()
91
    {
92
        return [
93 1
            'template_type' => $this->getType(),
94 1
            'elements' => $this->elements,
95 1
            'buttons' => $this->button ? [$this->button] : null,
96 1
            'top_element_style' => $this->topElementStyle,
97 1
        ];
98
    }
99
}
100