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

ImageVariable   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
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 4 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 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