Total Complexity | 7 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | trait HasSeoEntity |
||
8 | { |
||
9 | /** |
||
10 | * Get seo information relationship. |
||
11 | */ |
||
12 | 8 | public function seo_info(): \Illuminate\Database\Eloquent\Relations\MorphOne |
|
13 | { |
||
14 | 8 | return $this->morphOne(\NovaSeoEntity\Models\SEOInfo::class, 'seoptimisable'); |
|
|
|||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Get seo information relationship with default value. |
||
19 | */ |
||
20 | 2 | public function seo_info_forced(): \Illuminate\Database\Eloquent\Relations\MorphOne |
|
21 | { |
||
22 | 2 | return $this->morphOne(\NovaSeoEntity\Models\SEOInfo::class, 'seoptimisable') |
|
23 | 2 | ->withDefault([ |
|
24 | 2 | 'seoptimisable_type' => $this->getMorphClass(), |
|
25 | 2 | 'seoptimisable_id' => $this->getKey(), |
|
26 | 2 | ]); |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * Get default value. |
||
31 | * |
||
32 | * @param string $key |
||
33 | * |
||
34 | * @return mixed |
||
35 | */ |
||
36 | 2 | public function getNewInstanceSeoValueFor(string $key): mixed |
|
37 | { |
||
38 | 2 | $method = 'getNewInstanceSeoValueFor' . Str::ucfirst(Str::camel($key)); |
|
39 | 2 | if (method_exists($this, $method)) { |
|
40 | 2 | return $this->$method(); |
|
41 | } |
||
42 | |||
43 | 2 | if (method_exists($this, 'getAttribute')) { |
|
44 | 2 | return $this->getAttribute($key); |
|
45 | } |
||
46 | |||
47 | 1 | return null; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get value for. |
||
52 | * |
||
53 | * @param string $key |
||
54 | * @param mixed|null $value |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 2 | public function getSEOFieldValue(string $key, mixed $value = null): mixed |
|
66 | } |
||
67 | } |
||
68 |