ImageElement::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 9
cp 0.7778
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0987
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\MessageTypeEnum;
16
use App\Slack\MessageBuilder\MessageJsonSerializeTrait;
17
18
class ImageElement implements SectionBlockElementInterface, ContextBlockElementInterface
19
{
20
    use MessageJsonSerializeTrait;
21
22
    /** @var string */
23
    private $type;
24
    /** @var string */
25
    private $imageUrl;
26
    /** @var string */
27
    private $altText;
28
29 1
    public function __construct(string $imageUrl, string $altText)
30
    {
31 1
        if (\strlen($imageUrl) > 3000) {
32
            throw new \InvalidArgumentException('$imageUrl too long!');
33
        }
34 1
        if (\strlen($altText) > 2000) {
35
            throw new \InvalidArgumentException('$altText too long!');
36
        }
37
38 1
        $this->type = MessageTypeEnum::ELEMENT_IMAGE;
39 1
        $this->imageUrl = $imageUrl;
40 1
        $this->altText = $altText;
41 1
    }
42
}
43