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

Homepage::is()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 4
nc 2
nop 2
crap 4
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