BaseConfig   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
c 0
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A errorSummary() 0 5 2
A removeValue() 0 10 2
1
<?php
2
3
namespace thoulah\fontawesome\config;
4
5
use yii\base\DynamicModel;
6
use yii\helpers\Html;
7
8
/**
9
 * Base for configuration, meant to be extended.
10
 */
11
class BaseConfig extends \yii\base\BaseObject
12
{
13
    /** @var array supported bootstrap versions */
14
    protected const VALID_BOOTSTRAP = ['bootstrap4'];
15
16
    /** @var array valid options of `groupSize` */
17
    protected const VALID_GROUPSIZES = ['sm', 'md', 'lg'];
18
19
    /** @var array valid options of `style` */
20
    protected const VALID_STYLES = ['solid', 'regular', 'light', 'brands'];
21
22
    /**
23
     * Removes an item from the object and returns the value. If the key does not
24
     * exist in the object, the default value will be returned instead.
25
     *
26
     * @param string $key     Key name of the object element
27
     * @param mixed  $default The default value to be returned if the specified key does not exist
28
     */
29
    public function removeValue(string $key, $default = null)
30
    {
31
        if (isset($this->$key)) {
32
            $value = $this->$key;
33
            unset($this->$key);
34
35
            return $value;
36
        }
37
38
        return $default;
39
    }
40
41
    /**
42
     * Checks if validation returned errors and returns the errors.
43
     *
44
     * @param DynamicModel $model Validation model
45
     *
46
     * @return string|null Validation errors
47
     */
48
    protected function errorSummary(DynamicModel $model): ?string
49
    {
50
        return ($model->hasErrors())
51
            ? Html::errorSummary($model)
52
            : null;
53
    }
54
}
55