Passed
Branch v2 (aaaa8e)
by Brent
03:38
created

Image::alt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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