Passed
Push — develop ( 28eec5...3846cd )
by Paul
13:41
created

ElementTrait::badge()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 4
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 2
b 0
f 2
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\Breakdance;
4
5
use GeminiLabs\SiteReviews\Contracts\ShortcodeContract;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
use GeminiLabs\SiteReviews\Helpers\Str;
8
9
trait ElementTrait
10
{
11
    /**
12
     * @return array
13
     */
14
    public static function actions()
15
    {
16
        return glsr()->filterArray('breakdance/actions',
17
            static::bdActions(),
18
            static::bdShortcode()
19
        );
20
    }
21
22
    /**
23
     * @return array
24
     */
25
    public static function badge()
26
    {
27
        return [
28
            'backgroundColor' => '',
29
            'label' => ' ', // empty because we use this to display an icon
30
            'textColor' => '',
31
        ];
32
    }
33
34
    public static function bdActions(): array
35
    {
36
        return [
37
            'onMountedElement' => [[
38
                'script' => 'GLSR_init();',
39
            ]],
40
            // 'onPropertyChange' => [[
41
            //     'script' => 'GLSR_init();',
42
            // ]],
43
        ];
44
    }
45
46
    public static function bdDependencies(): array
47
    {
48
        return [
49
            [
50
                'builderCondition' => 'return true;',
51
                'frontendCondition' => 'return false;',
52
                'inlineStyles' => [
53
                    '%%SELECTOR%% a, %%SELECTOR%% button {pointer-events: none}',
54
                ],
55
            ],
56
        ];
57
    }
58
59
    abstract public static function bdShortcode(): ShortcodeContract;
60
61
    abstract public static function bdShortcodeClass(): string;
62
63
    /**
64
     * @return string
65
     */
66
    public static function category()
67
    {
68
        return glsr()->id;
69
    }
70
71
    public static function cssTemplate()
72
    {
73
        return glsr()->filterString('breakdance/css_template',
74
            static::bdFileContents('css.twig'),
75
            static::bdShortcode()
76
        );
77
    }
78
79
    public static function className()
80
    {
81
        return 'breakdance-'.Str::dashCase(static::bdShortcode()->tag);
82
    }
83
84
    public static function defaultCss()
85
    {
86
        return glsr()->filterString('breakdance/default_css',
87
            static::bdFileContents('default.css'),
88
            static::bdShortcode()
89
        );
90
    }
91
92
    public static function dependencies()
93
    {
94
        return glsr()->filterArray('breakdance/dependencies',
95
            static::bdDependencies(),
96
            static::bdShortcode()
97
        );
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public static function name()
104
    {
105
        return static::bdShortcode()->name();
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public static function nestingRule()
112
    {
113
        return [
114
            'type' => 'final',
115
        ];
116
    }
117
118
    /**
119
     * @return string[]
120
     */
121
    public static function propertyPathsToSsrElementWhenValueChanges()
122
    {
123
        return [
124
            'content',
125
            // 'design',
126
        ];
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public static function settings()
133
    {
134
        return [
135
            'bypassPointerEvents' => true,
136
            'disableAI' => true,
137
        ];
138
    }
139
140
    /**
141
     * @return array[]
142
     */
143
    public static function settingsControls()
144
    {
145
        return [];
146
    }
147
148
    /**
149
     * @param mixed $propertiesData
150
     * @param mixed $parentPropertiesData
151
     * @param bool  $isBuilder
152
     * @param int   $repeaterItemNodeId
153
     *
154
     * @return string
155
     */
156
    public static function ssr($propertiesData, $parentPropertiesData = [], $isBuilder = false, $repeaterItemNodeId = null)
157
    {
158
        $args = static::ssrArgs(Arr::consolidate($propertiesData));
159
        return static::bdShortcode()->build($args, 'breakdance', false);
160
    }
161
162
    abstract public static function ssrArgs(array $propertiesData): array;
163
164
    /**
165
     * @return string
166
     */
167
    public static function slug()
168
    {
169
        return __CLASS__;
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public static function template()
176
    {
177
        return '%%SSR%%';
178
    }
179
180
    protected static function bdFileContents(string $file): string
181
    {
182
        $reflector = new \ReflectionClass(static::class);
183
        $dir = dirname($reflector->getFileName());
184
        $file = "{$dir}/$file";
185
        return file_exists($file) ? file_get_contents($file) : '';
186
    }
187
}
188