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

ImageVariable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A make() 0 6 1
A parse() 0 15 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
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