BaseTemplate::mutateAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Thinkone\NovaPageSettings\Templates;
4
5
use Illuminate\Support\Str;
6
use Thinkone\NovaPageSettings\Model\PageSettingsCollection;
7
8
abstract class BaseTemplate implements SettingsTemplate
9
{
10
    /**
11
     * @deprecated
12
     * @codeCoverageIgnore
13
     */
14
    public static function retreive(?string $modelClass = null): PageSettingsCollection
15
    {
16
        return static::retrieve($modelClass);
17
    }
18
19 1
    public static function retrieve(?string $modelClass = null): PageSettingsCollection
20
    {
21 1
        $modelClass = $modelClass ?? config('nova-page-settings.default.settings_model');
22
23 1
        return $modelClass::page(static::getSlug())->get();
24
    }
25
26 1
    public static function viewData(array $options = []): array
27
    {
28 1
        $pageSettingsCollection = static::retrieve($options['modelClass'] ?? null);
29
30 1
        return  $pageSettingsCollection->pluck('value', 'key')->all();
31
    }
32
33 2
    public static function getSlug(): string
34
    {
35 2
        return Str::slug(static::getName());
36
    }
37
38 4
    public static function getName(): string
39
    {
40 4
        return Str::title(Str::snake(array_reverse(explode('\\', static::class))[0], ' '));
41
    }
42
43 1
    public function mutateAttribute($key, $value)
44
    {
45 1
        $methodName = 'get' . Str::studly($key) . 'Attribute';
46
47 1
        if (method_exists($this, $methodName)) {
48 1
            return $this->$methodName($value);
49
        }
50
51 1
        return $value;
52
    }
53
54 2
    public function templateKey(string $key): string
55
    {
56 2
        return config('nova-page-settings.key_prefix') . $key;
57
    }
58
}
59