IconWidget4   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
c 2
b 0
f 0
dl 0
loc 24
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 1
1
<?php
2
3
namespace thoulah\fontawesome;
4
5
use thoulah\fontawesome\config\Defaults;
6
use thoulah\fontawesome\helpers\Image;
7
8
/**
9
 * Provides an easy way to access icons as a widget.
10
 *
11
 * ```php
12
 * use thoulah\fontawesome\IconWidget4 as IconWidget;
13
 * echo IconWidget::widget(['name' => 'at']);
14
 *
15
 * echo IconWidget::widget([
16
 *     'name' => 'github',
17
 *     'options' => [
18
 *         'style' => 'brands',
19
 *         'fill' => '#003865'
20
 *     ]
21
 * ]);
22
 *
23
 * echo IconWidget::widget([
24
 *     'name' => 'font-awesome',
25
 *     'options' => [
26
 *         'class' => 'yourClass',
27
 *         'style' => 'brands'
28
 *     ],
29
 * ]);
30
 * ```
31
 */
32
class IconWidget4 extends \yii\bootstrap4\Widget
33
{
34
    /** @var array|null overrides of the default settings */
35
    public static $defaults;
36
37
    /** @var string name of the icon */
38
    public $name;
39
40
    /** @var array icon settings */
41
    public $options = [];
42
43
    /**
44
     * Executes the widget.
45
     *
46
     * @return string The icon
47
     */
48
    public function run(): string
49
    {
50
        $defaults = new Defaults(static::$defaults ?? []);
51
        $image = new Image($defaults);
52
53
        $this->options['name'] = $this->name;
54
55
        return $image->get($this->options);
56
    }
57
}
58