Passed
Branch decouple-schema-constructors (7e448c)
by Caen
02:54
created

PageSchemaConstructor::constructPageSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Hyde\Framework\Concerns\FrontMatter\Schemas\Constructors;
4
5
use Hyde\Framework\Actions\Constructors\FindsNavigationDataForPage;
6
use Hyde\Framework\Actions\Constructors\FindsTitleForPage;
7
use Hyde\Framework\Hyde;
8
9
trait PageSchemaConstructor
10
{
11
    protected function constructPageSchema(): void
12
    {
13
        $this->title = FindsTitleForPage::run($this);
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
14
        $this->navigation = FindsNavigationDataForPage::run($this);
0 ignored issues
show
Bug Best Practice introduced by
The property navigation does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15
        $this->canonicalUrl = $this->makeCanonicalUrl();
0 ignored issues
show
Bug Best Practice introduced by
The property canonicalUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
    }
17
18
    protected function makeCanonicalUrl(): ?string
19
    {
20
        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

20
        if (! empty($this->/** @scrutinizer ignore-call */ matter('canonicalUrl'))) {
Loading history...
21
            return $this->matter('canonicalUrl');
22
        }
23
24
        if (Hyde::hasSiteUrl() && ! empty($this->identifier)) {
25
            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

25
            return $this->/** @scrutinizer ignore-call */ getRoute()->getQualifiedUrl();
Loading history...
26
        }
27
28
        return null;
29
    }
30
}
31