Completed
Pull Request — master (#38)
by
unknown
03:25
created

OptionGroup::setLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
namespace Maknz\Slack\Object;
3
4
use InvalidArgumentException;
5
use Maknz\Slack\OptionsTrait;
6
use Maknz\Slack\BlockElement\Text;
7
8
class OptionGroup extends CompositionObject
9
{
10
    use OptionsTrait;
11
12
    /**
13
     * Option group label.
14
     *
15
     * @var Maknz\Slack\BlockElement\Text
0 ignored issues
show
Bug introduced by
The type Maknz\Slack\Object\Maknz\Slack\BlockElement\Text was not found. Did you mean Maknz\Slack\BlockElement\Text? If so, make sure to prefix the type with \.
Loading history...
16
     */
17
    protected $label;
18
19
    /**
20
     * Internal attribute to property map.
21
     *
22
     * @var array
23
     */
24
    protected static $availableAttributes = [
25
        'label'   => 'label',
26
        'options' => 'options',
27
    ];
28
29
    /**
30
     * Get the option group label.
31
     *
32
     * @return Maknz\Slack\BlockElement\Text
33
     */
34 2
    public function getLabel()
35
    {
36 2
        return $this->label;
37
    }
38
39
    /**
40
     * Set the option group label.
41
     *
42
     * @param mixed $label
43
     *
44
     * @return OptionGroup
45
     *
46
     * @throws \InvalidArgumentException
47
     */
48 7
    public function setLabel($label)
49
    {
50 7
        $this->label = Text::create($label, Text::TYPE_PLAIN);
0 ignored issues
show
Documentation Bug introduced by
It seems like Maknz\Slack\BlockElement...ement\Text::TYPE_PLAIN) of type Maknz\Slack\BlockElement\Text is incompatible with the declared type Maknz\Slack\Object\Maknz\Slack\BlockElement\Text of property $label.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
52 7
        return $this;
53
    }
54
55
    /**
56
     * Get whether the option group has a selected option
57
     *
58
     * @return bool
59
     */
60 4
    public function hasSelectedOption()
61
    {
62 4
        foreach ($this->getOptions() as $option) {
63 4
            if ($option->isInitiallySelected()) {
64 4
                return true;
65
            }
66
        }
67
68 3
        return false;
69
    }
70
71
    /**
72
     * Convert the block to its array representation.
73
     *
74
     * @return array
75
     */
76 2
    public function toArray()
77
    {
78
        $data = [
79 2
            'label'   => $this->getLabel()->toArray(),
80 2
            'options' => $this->getOptionsAsArrays(),
81
        ];
82
83 2
        return $data;
84
    }
85
}
86