FontPickerField::getDefaultFont()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 1
c 2
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\Fontpicker\Forms;
4
5
use SilverStripe\Forms\SingleSelectField;
6
use SilverStripe\View\Requirements;
7
8
class FontPickerField extends SingleSelectField
9
{
10
    /**
11
     * Defines the default font
12
     *
13
     * @config
14
     * @var array
15
     */
16
    protected static $default_font = 'nunito-sans';
17
18
    public function getDefaultFont()
19
    {
20
        return $this->owner->config()->get('default_font');
0 ignored issues
show
Bug introduced by
The method config() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        return $this->owner->/** @scrutinizer ignore-call */ config()->get('default_font');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property owner does not exist on SilverStripe\Fontpicker\Forms\FontPickerField. Since you implemented __get, consider adding a @property annotation.
Loading history...
21
    }
22
23
    public function __construct($name, $title = null, $source = array(), $value = null)
24
    {
25
        parent::__construct($name, $title, $source, $value);
26
27
        $this->addExtraClass('font-picker-field');
28
    }
29
30
    public function getSchemaDataDefaults()
31
    {
32
        $schemaData = parent::getSchemaDataDefaults();
33
34
        $fonts = [];
35
        foreach ($this->getSource() as $css => $title) {
36
            $fonts[] = [
37
                'CSSClass' => $css,
38
                'Title' => $title,
39
            ];
40
        }
41
42
        $schemaData['source'] = $fonts;
43
        $schemaData['name'] = $this->getName();
44
        $schemaData['value'] = $this->Value();
45
46
        return $schemaData;
47
    }
48
49
    public function Value()
50
    {
51
        return parent::Value() ?: $this->getDefaultFont();
52
    }
53
}
54