Completed
Push — master ( 328857...405b9d )
by Basenko
03:28
created

TemplatableField   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 37
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A parseValue() 0 12 3
A getTemplatePath() 0 6 1
A getNestingLevel() 0 4 1
1
<?php
2
3
namespace MadWeb\Seoable\Fields;
4
5
abstract class TemplatableField extends Field
6
{
7
    /** @var string */
8
    protected $templateKey;
9
10 9
    public function __construct($value, $model, string $templateKey = '')
11
    {
12 9
        $this->templateKey = $templateKey;
13
14 9
        parent::__construct($value, $model);
15 9
    }
16
17 9
    protected function parseValue($value): string
18
    {
19 9
        $nesting_level = $this->templateKey ?: $this->getNestingLevel();
20
21 9
        return trans(
22 9
            $this->getTemplatePath(
23 9
                get_class($this->model).
24 9
                ($nesting_level ? '.'.$nesting_level : '')
25
            ),
26 9
            $this->parseAttributesWithKeys($value)
27
        );
28
    }
29
30 9
    protected function getTemplatePath(string $templateKey): string
31
    {
32 9
        return config('seoable.templates_path').
33 9
            '.'.$templateKey.'.'.
34 9
            mb_strtolower(class_basename($this));
35
    }
36
37 3
    protected function getNestingLevel(): string
38
    {
39 3
        return '';
40
    }
41
}
42