Defaults::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace thoulah\fontawesome\config;
4
5
use yii\base\DynamicModel;
6
use yii\helpers\ArrayHelper;
7
8
/**
9
 * Sets default opions.
10
 *
11
 * @return self default values
12
 */
13
class Defaults extends BaseConfig
14
{
15
    /**
16
     * @var bool ActiveForm specific option. Sets fixed width icons.
17
     *           Set to `false` to have variable width icons. Overrules `fixedWidth`
18
     */
19
    public $activeFormFixedWidth = true;
20
21
    /** @var bool ActiveForm specific option. Whether to prepend or append the `input-group` */
22
    public $append = false;
23
24
    /** @var string Bootstrap namespace to use – Currently the only supported option */
25
    public $bootstrap = 'bootstrap4';
26
27
    /** @var string Backup icon in case requested icon cannot be found */
28
    public $fallbackIcon = '@vendor/fortawesome/font-awesome/svgs/solid/question-circle.svg';
29
30
    /** @var string Color of the icon. Set to empty string to disable this attribute */
31
    public $fill = 'currentColor';
32
33
    /** @var bool Set to `true` to have fixed width icons */
34
    public $fixedWidth = false;
35
36
    /**
37
     * @var string Path to your Font Awesome installation
38
     *             Usable for Font Awesome Pro
39
     */
40
    public $fontAwesomeFolder = '@vendor/fortawesome/font-awesome/svgs';
41
42
    /** @var string ActiveForm specific option. Set to `sm` for small or `lg` for large */
43
    public $groupSize = 'md';
44
45
    /** @var string CSS class basename, requires custom CSS if changed */
46
    public $prefix = 'svg-inline--fa';
47
48
    /** @var bool Whether or not to register the Font Awesome assets. */
49
    public $registerAssets = true;
50
51
    /**
52
     * @var string See
53
     *             [Referencing Icons](https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use)
54
     *             Usable for Font Awesome Pro
55
     */
56
    public $style = 'solid';
57
58
    /**
59
     * Creates a new Defaults object.
60
     *
61
     * @param array $defaults overrides of the default settings
62
     */
63
    public function __construct(array $defaults = [])
64
    {
65
        $allowedDefaults = array_intersect_key($defaults, get_class_vars(__CLASS__));
66
        parent::__construct($allowedDefaults);
67
    }
68
69
    /**
70
     * Validate the defaults.
71
     *
72
     * @return string|null Validation errors
73
     */
74
    public function validate(): ?string
75
    {
76
        $model = DynamicModel::validateData(
77
            ArrayHelper::toArray($this),
78
            [
79
                [['activeFormFixedWidth', 'append', 'fixedWidth', 'registerAssets'], 'boolean'],
80
                [['bootstrap'], 'in', 'range' => self::VALID_BOOTSTRAP],
81
                [['fill', 'fallbackIcon', 'fontAwesomeFolder', 'prefix'], 'string'],
82
                [['groupSize'], 'in', 'range' => self::VALID_GROUPSIZES],
83
                [['style'], 'in', 'range' => self::VALID_STYLES],
84
            ]
85
        );
86
87
        return $this->errorSummary($model);
88
    }
89
}
90