ConfirmationDialogObject::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.583

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 10
cts 14
cp 0.7143
rs 9.2888
c 0
b 0
f 0
cc 5
nc 5
nop 4
crap 5.583
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\Object;
14
15
use App\Slack\MessageBuilder\Element\PlainTextElement;
16
use App\Slack\MessageBuilder\Element\TextElementInterface;
17
use App\Slack\MessageBuilder\MessageInterface;
18
use App\Slack\MessageBuilder\MessageJsonSerializeTrait;
19
20
class ConfirmationDialogObject implements MessageInterface
21
{
22
    use MessageJsonSerializeTrait;
23
24
    /** @var PlainTextElement */
25
    private $title;
26
    /** @var TextElementInterface */
27
    private $text;
28
    /** @var PlainTextElement */
29
    private $confirm;
30
    /** @var PlainTextElement */
31
    private $deny;
32
33 2
    public function __construct(string $title, TextElementInterface $text, string $confirm, string $deny)
34
    {
35 2
        if (\strlen($title) > 100) {
36
            throw new \InvalidArgumentException('$title too long!');
37
        }
38 2
        if (\strlen($text->jsonSerialize()['text']) > 300) {
39
            throw new \InvalidArgumentException('$text too long!');
40
        }
41 2
        if (\strlen($confirm) > 30) {
42
            throw new \InvalidArgumentException('$confirm too long!');
43
        }
44 2
        if (\strlen($deny) > 30) {
45
            throw new \InvalidArgumentException('$deny too long!');
46
        }
47
48 2
        $this->title = new PlainTextElement($title);
49 2
        $this->text = $text;
50 2
        $this->confirm = new PlainTextElement($confirm);
51 2
        $this->deny = new PlainTextElement($deny);
52 2
    }
53
}
54