GetSeo   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 1
Metric Value
eloc 9
c 6
b 2
f 1
dl 0
loc 20
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSeo() 0 3 1
A getGetSeoTitleAttribute() 0 13 5
1
<?php
2
3
namespace Larrock\Core\Traits;
4
5
use Cache;
6
use Larrock\Core\Models\Seo;
7
8
trait GetSeo
9
{
10
    public function getSeo()
11
    {
12
        return $this->hasOne(Seo::class, 'seo_id_connect', 'id')->whereSeoTypeConnect($this->config->name);
0 ignored issues
show
Bug introduced by
It seems like hasOne() 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 ignore-call  annotation

12
        return $this->/** @scrutinizer ignore-call */ hasOne(Seo::class, 'seo_id_connect', 'id')->whereSeoTypeConnect($this->config->name);
Loading history...
13
    }
14
15
    public function getGetSeoTitleAttribute()
16
    {
17
        $cache_key = sha1('getGetSeoTitleAttribute'.$this->id.$this->config->name);
18
19
        return Cache::rememberForever($cache_key, function () {
20
            if (($get_seo = Seo::whereSeoUrlConnect($this->url)->whereSeoTypeConnect($this->config->name)->first()) && $get_seo->seo_title) {
21
                return $get_seo->seo_title;
22
            }
23
            if (($get_seo = Seo::whereSeoIdConnect($this->id)->whereSeoTypeConnect($this->config->name)->first()) && $get_seo->seo_title) {
24
                return $get_seo->seo_title;
25
            }
26
27
            return $this->title;
28
        });
29
    }
30
}
31