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

Image   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 0 4 1
A src() 0 4 1
A srcset() 0 4 1
A sizes() 0 4 1
A alt() 0 4 1
A addSrcset() 0 8 1
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