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

TemplatableField::parseValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 1
crap 3
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