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

ImageVariable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A make() 0 4 1
A parse() 0 12 1
1
<?php
2
3
namespace Stitcher\Variable;
4
5
use Pageon\Html\Image\ImageFactory;
6
7
class ImageVariable extends AbstractVariable
8
{
9
    private $imageFactory;
10
    private $alt;
11
12
    public function __construct(string $src, ImageFactory $imageFactory, ?string $alt = '')
13
    {
14
        parent::__construct($src);
15
16
        $this->imageFactory = $imageFactory;
17
        $this->alt = $alt;
18
    }
19
20
    public static function make(string $value, ImageFactory $imageFactory, ?string $alt = '') : ImageVariable
21
    {
22
        return new self($value, $imageFactory, $alt);
23
    }
24
25
    public function parse() : AbstractVariable
26
    {
27
        $image = $this->imageFactory->create($this->unparsed);
28
29
        $this->parsed = [
30
            'src'    => $image->src(),
31
            'srcset' => $image->srcset(),
32
            'alt'    => $this->alt,
33
        ];
34
35
        return $this;
36
    }
37
}
38