Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
HasFactory | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
1 / 1 |
toCoreDataObject | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
constructFactoryData | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
assignFactoryData | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
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(), |
21 | $this->getOutputPath(), |
22 | $this->getRouteKey(), |
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 | } |