Test Failed
Push — master ( 22b809...326de4 )
by Brent
05:15 queued 39s
created

ImageVariable::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
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 2
    public function __construct($attributes, ImageFactory $imageFactory)
12
    {
13 2
        parent::__construct($attributes);
14
15 2
        $this->imageFactory = $imageFactory;
16 2
    }
17
18 2
    public static function make(
19
        $attributes,
20
        ImageFactory $imageFactory
21
    ) : ImageVariable {
22 2
        return new self($attributes, $imageFactory);
23
    }
24
25 2
    public function parse() : AbstractVariable
26
    {
27 2
        $src = $this->unparsed['src'] ?? $this->unparsed;
28 2
        $alt = $this->unparsed['alt'] ?? null;
29
30 2
        $image = $this->imageFactory->create($src);
31
32 2
        $this->parsed = [
33 2
            'src'    => $image->src(),
34 2
            'srcset' => $image->srcset(),
35 2
            'alt'    => $alt,
36
        ];
37
38 2
        return $this;
39
    }
40
}
41