Completed
Push — ft/remove-vendor ( 825fc6...4801b9 )
by Philippe
56:00 queued 47:37
created

Homepage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A is() 0 9 4
A url() 0 7 2
1
<?php
2
3
namespace Thinktomorrow\Chief\Settings;
4
5
use Thinktomorrow\Chief\Settings\Setting;
6
use Thinktomorrow\Chief\FlatReferences\FlatReferenceFactory;
7
use Thinktomorrow\Chief\FlatReferences\ProvidesFlatReference;
8
9
class Homepage
10
{
11 2
    public static function is($model, string $locale = null): bool
12
    {
13 2
        $homepageValue = chiefSetting(Setting::HOMEPAGE, $locale);
14
15 2
        if(!$homepageValue || !is_object($model) || !$model instanceof ProvidesFlatReference) {
16 2
            return false;
17
        }
18
19 1
        return $model->flatReference()->is($homepageValue);
20
    }
21
22 1
    public static function url($locale = null): string
23
    {
24 1
        if($id = chiefSetting(Setting::HOMEPAGE, $locale))
25
        {
26 1
            return FlatReferenceFactory::fromString($id)->instance()->url($locale);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Thinktomorrow\Chi...nstance()->url($locale) could return the type Illuminate\Database\Eloquent\Builder which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
27
        }
28
        return '';
29
    }
30
}
31