Image::alt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Pageon\Html\Image;
4
5
class Image
6
{
7
    private $src;
8
    private $srcset = [];
9
    private $sizes;
10
    private $alt;
11
12 7
    public function __construct(string $src, ?string $sizes = null, ?string $alt = null)
13
    {
14 7
        $this->src = "/{$src}";
15 7
        $this->sizes = $sizes;
16 7
        $this->alt = $alt;
17 7
    }
18
19 7
    public static function make(string $src, ?string $sizes = null, ?string $alt = null): Image
20
    {
21 7
        return new self($src, $sizes, $alt);
22
    }
23
24 4
    public function src(): string
25
    {
26 4
        return $this->src;
27
    }
28
29 3
    public function srcset(): string
30
    {
31 3
        return implode(', ', $this->srcset);
32
    }
33
34 1
    public function sizes(): ?string
35
    {
36 1
        return $this->sizes;
37
    }
38
39 1
    public function alt(): ?string
40
    {
41 1
        return $this->alt;
42
    }
43
44 4
    public function addSrcset(string $src, int $width): Image
45
    {
46 4
        $src = ltrim($src, '/');
47
48 4
        $this->srcset[] = "/{$src} {$width}w";
49
50 4
        return $this;
51
    }
52
}
53