Passed
Push — master ( 8ab35d...c4a5b0 )
by Caen
02:53 queued 11s
created

PageSchema::makeCanonicalUrl()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace Hyde\Framework\Concerns\FrontMatter\Schemas;
4
5
use Hyde\Framework\Actions\Constructors\FindsNavigationDataForPage;
6
use Hyde\Framework\Actions\Constructors\FindsTitleForPage;
7
use Hyde\Framework\Hyde;
8
use JetBrains\PhpStorm\ArrayShape;
9
10
trait PageSchema
11
{
12
    /**
13
     * The title of the page used in the HTML <title> tag, among others.
14
     *
15
     * @example "Home", "About", "Blog Feed"
16
     */
17
    public string $title;
18
19
    /**
20
     * The settings for how the page should be presented in the navigation menu.
21
     */
22
    #[ArrayShape(['title' => 'string', 'hidden' => 'bool', 'priority' => 'int'])]
23
    public ?array $navigation = null;
24
25
    /**
26
     * The canonical URL of the page.
27
     *
28
     * @var string|null
29
     */
30
    public ?string $canonicalUrl = null;
31
32
    protected function constructPageSchema(): void
33
    {
34
        $this->title = FindsTitleForPage::run($this);
35
        $this->navigation = FindsNavigationDataForPage::run($this);
36
        $this->canonicalUrl = $this->makeCanonicalUrl();
37
    }
38
39
    protected function makeCanonicalUrl(): ?string
40
    {
41
        if (! empty($this->matter('canonicalUrl'))) {
0 ignored issues
show
Bug introduced by
It seems like matter() 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

41
        if (! empty($this->/** @scrutinizer ignore-call */ matter('canonicalUrl'))) {
Loading history...
42
            return $this->matter('canonicalUrl');
43
        }
44
45
        if (Hyde::hasSiteUrl() && ! empty($this->identifier)) {
46
            return $this->getRoute()->getQualifiedUrl();
0 ignored issues
show
Bug introduced by
It seems like getRoute() 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

46
            return $this->/** @scrutinizer ignore-call */ getRoute()->getQualifiedUrl();
Loading history...
47
        }
48
49
        return null;
50
    }
51
}
52