Completed
Push — master ( efa9b4...b05f68 )
by wen
05:55
created

src/Form/Elements/Markdown.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
/**
6
 * Class Markdown
7
 *
8
 * @package Sco\Admin\Form\Elements
9
 * @see https://github.com/F-loat/vue-simplemde
10
 */
11
class Markdown extends NamedElement
12
{
13
    protected $type = 'markdown';
14
15
    /**
16
     * @var array
17
     */
18
    protected $configs;
19
20
    /**
21
     * @var bool
22
     */
23
    protected $highlight = true;
24
25
    /**
26
     * @var bool
27
     */
28
    protected $autoInit = true;
29
30
    /**
31
     * @return array
32
     */
33
    public function getConfigs(): array
34
    {
35
        if ($this->configs) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->configs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
36
            return $this->configs;
37
        }
38
39
        return $this->getDefaultConfigs();
40
    }
41
42
    /**
43
     * @return array
44
     */
45
    protected function getDefaultConfigs()
46
    {
47
        return [
48
            'autoDownloadFontAwesome' => false,
49
        ];
50
    }
51
52
    /**
53
     * @param array $configs
54
     *
55
     * @return Markdown
56
     */
57
    public function setConfigs(array $configs): Markdown
58
    {
59
        $this->configs = $configs;
60
61
        return $this;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    public function isHighlight(): bool
68
    {
69
        return $this->highlight ? true : false;
70
    }
71
72
    /**
73
     *
74
     * @return Markdown
75
     */
76
    public function disableHighlight(): Markdown
77
    {
78
        $this->highlight = false;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @return bool
85
     */
86
    public function isAutoInit(): bool
87
    {
88
        return $this->autoInit ? true : false;
89
    }
90
91
    /**
92
     *
93
     * @return Markdown
94
     */
95
    public function disableAutoInit(): Markdown
96
    {
97
        $this->autoInit = false;
98
99
        return $this;
100
    }
101
102
    public function toArray()
103
    {
104
        return parent::toArray() + [
105
                'configs'   => $this->getConfigs(),
106
                'highlight' => $this->isHighlight(),
107
                'autoInit'  => $this->isAutoInit(),
108
            ];
109
    }
110
}
111