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.
Passed
Pull Request — master (#36)
by Gallice
04:29
created

ElementList::__construct()   B

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
     * @var Element[]
15
     */
16
    private $elements;
17
18
    /**
19
     * @var ButtonModel|null
20
     */
21
    private $button;
22
23
    /**
24
     * @var string
25
     */
26
    private $topElementStyle;
27
28
    /**
29
     * @param Element[] $elements
30
     * @param ButtonModel|null $button
31
     * @param string $topElementStyle
32
     */
33 11
    public function __construct(array $elements, ButtonModel $button = null, $topElementStyle = self::TOP_STYLE_LARGE)
34
    {
35 11
        if (empty($elements) || (count($elements) < 2 || count($elements) > 4)) {
36 3
            throw new \InvalidArgumentException('You must provide between 2 and 4 elements.');
37
        }
38
39 8
        $topElementStyle = strtolower($topElementStyle);
40
41 8
        if (!in_array($topElementStyle, [self::TOP_STYLE_LARGE, self::TOP_STYLE_COMPACT])) {
42
            throw new \InvalidArgumentException(sprintf('"%s" is not a valid top element style.', $topElementStyle));
43
        }
44
45 8
        if ($topElementStyle === self::TOP_STYLE_LARGE && empty($elements[0]->getImageUrl())) {
46
            throw new \InvalidArgumentException(sprintf('If the top element style is "%s" your first element must have an image url', self::TOP_STYLE_LARGE));
47
        }
48
49 8
        $this->elements = $elements;
50 8
        $this->button = $button;
51 8
        $this->topElementStyle = $topElementStyle;
52 8
    }
53
54
    /**
55
     * @return Element[]
56
     */
57 1
    public function getElements()
58
    {
59 1
        return $this->elements;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 2
    public function getTopElementStyle()
66
    {
67 2
        return $this->topElementStyle;
68
    }
69
70
    /***
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
71
     * @return null|ButtonModel
72
     */
73 1
    public function getButton()
74
    {
75 1
        return $this->button;
76
    }
77
78
    /**
79
     * @return string
80
     */
81 2
    public function getType()
82
    {
83 2
        return Template::TYPE_LIST;
84
    }
85
86
    /**
87
     * @inheritdoc
88
     */
89 1
    public function jsonSerialize()
90
    {
91
        return [
92 1
            'template_type' => $this->getType(),
93 1
            'elements' => $this->elements,
94 1
            'buttons' => $this->button ? [$this->button] : null,
95 1
            'top_element_style' => $this->topElementStyle,
96 1
        ];
97
    }
98
}
99