BreadcrumbAssistant   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 43
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A manager() 0 3 1
A fields() 0 8 1
A key() 0 3 1
A saveParentPageField() 0 3 1
A can() 0 3 1
A guard() 0 3 1
A route() 0 3 1
1
<?php  declare(strict_types = 1);
2
3
namespace Thinktomorrow\ChiefSitestructure\Breadcrumbs;
4
5
use Illuminate\Http\Request;
6
use Thinktomorrow\Chief\Fields\Fields;
7
use Thinktomorrow\Chief\Urls\UrlHelper;
8
use Thinktomorrow\Chief\Management\Manager;
9
use Thinktomorrow\Chief\Fields\Types\SelectField;
10
use Thinktomorrow\ChiefSitestructure\SiteStructure;
11
use Thinktomorrow\Chief\Management\Assistants\Assistant;
12
13
class BreadcrumbAssistant implements Assistant
14
{
15
    private $manager;
16
17
    public function manager(Manager $manager)
18
    {
19
        $this->manager  = $manager;
20
    }
21
22
    public static function key(): string
23
    {
24
        return 'breadcrumbs';
25
    }
26
27
    public function route($verb): ?string
28
    {
29
        return null;
30
    }
31
32
    public function fields(): Fields
33
    {
34
        return new Fields([
35
            SelectField::make('parent_page')
36
                ->options(UrlHelper::allModelsExcept($this->manager->modelInstance()))
37
                ->selected(app(Breadcrumbs::class)->getParentForPage($this->manager->modelInstance()))
38
                ->grouped()
39
                ->label('De pagina waar deze pagina onder hoort.'),
40
        ]);
41
    }
42
43
    public function saveParentPageField($field, Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

43
    public function saveParentPageField(/** @scrutinizer ignore-unused */ $field, Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
    {
45
        app(SiteStructure::class)->save($this->manager->existingModel()->flatreference()->get(), $request->input('parent_page') ?? null);
46
    }
47
48
    public function can($verb): bool
49
    {
50
        return true;
51
    }
52
53
    public function guard($verb): Assistant
0 ignored issues
show
Unused Code introduced by
The parameter $verb is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

53
    public function guard(/** @scrutinizer ignore-unused */ $verb): Assistant

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55
        return $this;
56
    }
57
}
58