Passed
Push — master ( 25efb9...c70e91 )
by Caen
04:09 queued 12s
created

HasFactory::assignFactoryData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Factories\Concerns;
6
7
use Hyde\Framework\Factories\BlogPostDataFactory;
8
use Hyde\Framework\Factories\HydePageDataFactory;
9
use Hyde\Pages\MarkdownPost;
10
11
trait HasFactory
12
{
13
    public function toCoreDataObject(): CoreDataObject
14
    {
15
        return new CoreDataObject(
16
            $this->matter,
17
            $this->markdown ?? false,
18
            static::class,
19
            $this->identifier,
20
            $this->getSourcePath(),
0 ignored issues
show
Bug introduced by
It seems like getSourcePath() 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
            $this->/** @scrutinizer ignore-call */ 
21
                   getSourcePath(),
Loading history...
21
            $this->getOutputPath(),
0 ignored issues
show
Bug introduced by
It seems like getOutputPath() 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

21
            $this->/** @scrutinizer ignore-call */ 
22
                   getOutputPath(),
Loading history...
22
            $this->getRouteKey(),
0 ignored issues
show
Bug introduced by
It seems like getRouteKey() 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

22
            $this->/** @scrutinizer ignore-call */ 
23
                   getRouteKey(),
Loading history...
23
        );
24
    }
25
26
    protected function constructFactoryData(): void
27
    {
28
        $this->assignFactoryData(new HydePageDataFactory($this->toCoreDataObject()));
29
30
        if ($this instanceof MarkdownPost) {
31
            $this->assignFactoryData(new BlogPostDataFactory($this->toCoreDataObject()));
32
        }
33
    }
34
35
    protected function assignFactoryData(PageDataFactory $factory): void
36
    {
37
        foreach ($factory->toArray() as $key => $value) {
38
            $this->{$key} = $value;
39
        }
40
    }
41
}
42