Passed
Push — master ( 856b52...5c51b9 )
by Caen
03:00 queued 12s
created

ManagesHydeKernel::getBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Concerns;
6
7
use Hyde\Foundation\FileCollection;
8
use Hyde\Foundation\HydeKernel;
9
use Hyde\Foundation\PageCollection;
10
use Hyde\Foundation\RouteCollection;
11
use Hyde\Pages\Concerns\HydePage;
12
13
/**
14
 * @internal Single-use trait for the HydeKernel class.
15
 *
16
 * @see \Hyde\Foundation\HydeKernel
17
 */
18
trait ManagesHydeKernel
19
{
20
    public function boot(): void
21
    {
22
        $this->booted = true;
0 ignored issues
show
Bug Best Practice introduced by
The property booted does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
24
        $this->files = FileCollection::boot($this);
0 ignored issues
show
Bug Best Practice introduced by
The property files does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
        $this->pages = PageCollection::boot($this);
0 ignored issues
show
Bug Best Practice introduced by
The property pages does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
        $this->routes = RouteCollection::boot($this);
0 ignored issues
show
Bug Best Practice introduced by
The property routes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
    }
28
29
    public static function getInstance(): HydeKernel
30
    {
31
        return static::$instance;
32
    }
33
34
    public static function setInstance(HydeKernel $instance): void
35
    {
36
        static::$instance = $instance;
0 ignored issues
show
Bug Best Practice introduced by
The property instance does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
    }
38
39
    public function setBasePath(string $basePath): void
40
    {
41
        $this->basePath = rtrim($basePath, '/\\');
0 ignored issues
show
Bug Best Practice introduced by
The property basePath does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
42
    }
43
44
    public function getBasePath(): string
45
    {
46
        return $this->basePath;
47
    }
48
49
    public function setSourceRoot(string $sourceRoot): void
50
    {
51
        $this->sourceRoot = rtrim($sourceRoot, '/\\');
0 ignored issues
show
Bug Best Practice introduced by
The property sourceRoot does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
52
    }
53
54
    public function getSourceRoot(): string
55
    {
56
        return $this->sourceRoot;
57
    }
58
59
    /** @return array<class-string<\Hyde\Pages\Concerns\HydePage>> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string<\Hyde...ges\Concerns\HydePage>> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string<\Hyde\Pages\Concerns\HydePage>>.
Loading history...
60
    public function getDiscoveredPageTypes(): array
61
    {
62
        return $this->pages()->map(function (HydePage $page): string {
0 ignored issues
show
Bug introduced by
It seems like pages() 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

62
        return $this->/** @scrutinizer ignore-call */ pages()->map(function (HydePage $page): string {
Loading history...
63
            return $page::class;
64
        })->unique()->values()->toArray();
65
    }
66
}
67