ImageBlock   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 33
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 5
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\Block;
14
15
use App\Slack\MessageBuilder\Element\PlainTextElement;
16
use App\Slack\MessageBuilder\Enum\MessageTypeEnum;
17
use App\Slack\MessageBuilder\MessageJsonSerializeTrait;
18
19
class ImageBlock implements BlockInterface
20
{
21
    use MessageJsonSerializeTrait;
22
23
    /** @var string */
24
    private $type;
25
    /** @var string */
26
    private $imageUrl;
27
    /** @var string */
28
    private $altText;
29
    /** @var PlainTextElement|null */
30
    private $title;
31
32
    public function __construct(string $imageUrl, string $altText, string $title = '')
33
    {
34
        if (\strlen($imageUrl) > 3000) {
35
            throw new \InvalidArgumentException('$imageUrl too long!');
36
        }
37
        if (\strlen($altText) > 2000) {
38
            throw new \InvalidArgumentException('$altText too long!');
39
        }
40
        if (\strlen($title) > 2000) {
41
            throw new \InvalidArgumentException('$altText too long!');
42
        }
43
44
        $this->type = MessageTypeEnum::BLOCK_IMAGE;
45
        $this->imageUrl = $imageUrl;
46
        $this->altText = $altText;
47
        if ('' !== $title) {
48
            $this->title = new PlainTextElement($title);
49
        }
50
    }
51
}
52