ButtonElement::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5.3256

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 13
cts 17
cp 0.7647
rs 9.2408
c 0
b 0
f 0
cc 5
nc 5
nop 6
crap 5.3256
1
<?php
2
3
/** @noinspection 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\ButtonStyleEnum;
16
use App\Slack\MessageBuilder\Enum\MessageTypeEnum;
17
use App\Slack\MessageBuilder\MessageJsonSerializeTrait;
18
use App\Slack\MessageBuilder\Object\ConfirmationDialogObject;
19
20
class ButtonElement implements SectionBlockElementInterface, ActionsBlockElementInterface
21
{
22
    use MessageJsonSerializeTrait;
23
24
    /** @var string */
25
    private $type;
26
    /** @var PlainTextElement */
27
    private $text;
28
    /** @var string */
29
    private $actionId;
30
    /** @var ButtonStyleEnum|null */
31
    private $style;
32
    /** @var ConfirmationDialogObject|null */
33
    private $confirm;
34
    /** @var string */
35
    private $value;
36
    /** @var string */
37
    private $url;
38
39 2
    public function __construct(string $text, string $actionId, ButtonStyleEnum $style = null, ConfirmationDialogObject $confirm = null, string $value = '', string $url = '')
40
    {
41 2
        if (\strlen($text) > 75) {
42
            throw new \InvalidArgumentException('$text too long!');
43
        }
44 2
        if (\strlen($actionId) > 255) {
45
            throw new \InvalidArgumentException('$actionId too long!');
46
        }
47 2
        if (\strlen($value) > 2000) {
48
            throw new \InvalidArgumentException('$value too long!');
49
        }
50 2
        if (\strlen($url) > 3000) {
51
            throw new \InvalidArgumentException('$url too long!');
52
        }
53
54 2
        $this->type = MessageTypeEnum::ELEMENT_BUTTON;
55 2
        $this->text = new PlainTextElement($text);
56 2
        $this->actionId = $actionId;
57 2
        $this->style = $style;
58 2
        $this->confirm = $confirm;
59 2
        $this->value = $value;
60 2
        $this->url = $url;
61 2
    }
62
}
63