1 | <?php |
||||
2 | |||||
3 | namespace NovaSeoEntity\Models\Traits; |
||||
4 | |||||
5 | use Illuminate\Support\Str; |
||||
6 | |||||
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'); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
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(), |
|||
0 ignored issues
–
show
It seems like
getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
25 | 2 | 'seoptimisable_id' => $this->getKey(), |
|||
0 ignored issues
–
show
It seems like
getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
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 |
|||
59 | { |
||||
60 | 2 | $method = 'getSEO' . Str::ucfirst(Str::camel($key)) . 'FieldValue'; |
|||
61 | 2 | if (method_exists($this, $method)) { |
|||
62 | 2 | return $this->$method($value); |
|||
63 | } |
||||
64 | |||||
65 | 2 | return $value; |
|||
66 | } |
||||
67 | } |
||||
68 |