Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

ImageVariable::make()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
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 Stitcher\Variable;
4
5
use Pageon\Html\Image\ImageFactory;
6
7
class ImageVariable extends AbstractVariable
8
{
9
    private $imageFactory;
10
11 11
    public function __construct($attributes, ImageFactory $imageFactory)
12
    {
13 11
        parent::__construct($attributes);
14
15 11
        $this->imageFactory = $imageFactory;
16 11
    }
17
18 11
    public static function make($attributes, ImageFactory $imageFactory) : ImageVariable
19
    {
20 11
        return new self($attributes, $imageFactory);
21
    }
22
23 10
    public function parse() : AbstractVariable
24
    {
25 10
        $src = $this->unparsed['src'] ?? $this->unparsed;
26 10
        $alt = $this->unparsed['alt'] ?? null;
27
28 10
        $image = $this->imageFactory->create($src);
29
30 10
        $this->parsed = [
31 10
            'src'    => $image->src(),
32 10
            'srcset' => $image->srcset(),
33 10
            'alt'    => $alt,
34
        ];
35
36 10
        return $this;
37
    }
38
}
39