Failed Conditions
Push — master ( eac8ff...e4a057 )
by Zbigniew
04:46
created

MultiSelectStaticGroupElement::__construct()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.3906

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 12
cts 16
cp 0.75
rs 9.1768
c 0
b 0
f 0
cc 5
nc 5
nop 5
crap 5.3906
1
<?php
2
3
/** @noinspection DuplicatedCode, UnusedConstructorDependenciesInspection */
4
5
declare(strict_types=1);
6
7
/*
8
 * This file is part of the zibios/sharep.
9
 *
10
 * (c) Zbigniew Ślązak
11
 */
12
13
namespace App\Slack\MessageBuilder\Element;
14
15
use App\Slack\MessageBuilder\Enum\MessageTypeEnum;
16
use App\Slack\MessageBuilder\MessageJsonSerializeTrait;
17
use App\Slack\MessageBuilder\Object\ConfirmationDialogObject;
18
use App\Slack\MessageBuilder\Object\OptionGroupObject;
19
use App\Slack\MessageBuilder\Object\OptionObject;
20
21
class MultiSelectStaticGroupElement implements SectionBlockElementInterface, InputBlockElementInterface
22
{
23
    use MessageJsonSerializeTrait;
24
25
    /** @var string */
26
    private $type;
27
    /** @var PlainTextElement */
28
    private $placeholder;
29
    /** @var string */
30
    private $actionId;
31
    /** @var array|OptionObject[] */
32
    private $initialOptions;
33
    /** @var ConfirmationDialogObject */
34
    private $confirmDialog;
35
    /** @var array|OptionGroupObject[] */
36
    private $optionGroups;
37
38 1
    public function __construct(
39
        string $placeholder,
40
        string $actionId,
41
        array $initialOptions = [],
42
        ConfirmationDialogObject $confirmDialog = null,
43
        OptionGroupObject ...$optionGroups
44
    ) {
45 1
        if (\strlen($placeholder) > 150) {
46
            throw new \InvalidArgumentException('$text too long!');
47
        }
48 1
        if (\strlen($actionId) > 255) {
49
            throw new \InvalidArgumentException('$actionId too long!');
50
        }
51 1
        if (\count($optionGroups) > 100) {
52
            throw new \InvalidArgumentException('$optionGroups too long!');
53
        }
54 1
        if (0 === \count($optionGroups)) {
55
            throw new \InvalidArgumentException('$optionGroups too short!');
56
        }
57
58 1
        $this->type = MessageTypeEnum::ELEMENT_MULTI_SELECT_STATIC;
59 1
        $this->placeholder = new PlainTextElement($placeholder);
60 1
        $this->actionId = $actionId;
61 1
        $this->initialOptions = $initialOptions;
62 1
        $this->confirmDialog = $confirmDialog;
63 1
        $this->optionGroups = $optionGroups;
64 1
    }
65
}
66