Image   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 68
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getSvg() 0 9 1
A get() 0 6 1
A __toString() 0 3 1
1
<?php
2
3
namespace thoulah\fontawesome\helpers;
4
5
use thoulah\fontawesome\assets\FontAwesomeAsset;
6
use thoulah\fontawesome\config\Defaults;
7
use thoulah\fontawesome\config\Options;
8
use Yii;
9
10
/**
11
 * Helper class to load and manipulate images.
12
 */
13
class Image
14
{
15
    /** @var Defaults default options */
16
    private $defaults;
17
18
    /** @var object image data */
19
    private $image;
20
21
    /** @var Options individual icon options */
22
    private $options;
23
24
    /** @var string result of {@see Defaults} and {@see Options} validation */
25
    private $validation;
26
27
    /**
28
     * Creates a new Image object.
29
     *
30
     * @param Defaults $defaults default options
31
     */
32
    public function __construct(Defaults $defaults)
33
    {
34
        $this->defaults = $defaults;
35
        $this->validation = $this->defaults->validate();
36
37
        if ($this->defaults->registerAssets) {
38
            FontAwesomeAsset::register(Yii::$app->getView());
39
        }
40
    }
41
42
    /**
43
     * Magic function, returns the image string.
44
     *
45
     * @return string The SVG result
46
     */
47
    public function __toString(): string
48
    {
49
        return $this->validation . (string) $this->image;
50
    }
51
52
    /**
53
     * Load and process image.
54
     *
55
     * @param array $options options
56
     *
57
     * @return Svg Processed image data
58
     */
59
    public function get(array $options): Svg
60
    {
61
        $this->options = new Options($options);
62
        $this->validation .= $this->options->validate();
63
64
        return $this->getSvg();
65
    }
66
67
    /**
68
     * Load and process SVG data in correct order.
69
     *
70
     * @return Svg Processed SVG data
71
     */
72
    private function getSvg(): Svg
73
    {
74
        $this->image = new Svg($this->defaults, $this->options);
75
        $this->image->load();
76
        $this->image->getMeasurement();
77
        $this->image->getProperties();
78
        $this->image->setAttributes();
79
80
        return $this->image;
81
    }
82
}
83