Breadcrumbs   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getParentForPage() 0 9 2
A getFor() 0 3 1
A getForPage() 0 4 1
1
<?php declare(strict_types = 1);
2
3
namespace Thinktomorrow\ChiefSitestructure\Breadcrumbs;
4
5
use Thinktomorrow\Chief\Pages\Page;
6
use Thinktomorrow\ChiefSitestructure\SiteStructure;
7
8
class Breadcrumbs
9
{
10
    public static function getFor(string $flatreference)
11
    {
12
        return app(SiteStructure::class)->getForReference($flatreference);
13
    }
14
15
    public static function getForPage(Page $page)
16
    {
17
        return collect(static::getFor($page->flatreference()->get())->flatten()->all())->reject(function ($node) {
18
            return !$node->online;
19
        });
20
    }
21
22
    public static function getParentForPage(Page $page)
23
    {
24
        $structure = collect(static::getFor($page->flatreference()->get())->flatten()->all())->first();
25
26
        if ($structure) {
27
            return $structure->reference;
28
        }
29
30
        return null;
31
    }
32
}
33