Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
HasFeaturedImage | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
7 | |
100.00% |
1 / 1 |
constructFeaturedImage | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
constructBaseImage | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
constructFullImage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Hyde\Framework\Concerns; |
4 | |
5 | use Hyde\Framework\Models\Image; |
6 | |
7 | /** |
8 | * Handle logic for Page models that have a Featured Image. |
9 | * |
10 | * @see \Hyde\Framework\Models\Image |
11 | */ |
12 | trait HasFeaturedImage |
13 | { |
14 | public Image $image; |
15 | |
16 | public function constructFeaturedImage(): void |
17 | { |
18 | if (isset($this->matter['image'])) { |
19 | if (is_string($this->matter['image'])) { |
20 | $this->image = $this->constructBaseImage($this->matter['image']); |
21 | } |
22 | if (is_array($this->matter['image'])) { |
23 | $this->image = $this->constructFullImage($this->matter['image']); |
24 | } |
25 | } |
26 | } |
27 | |
28 | public function constructBaseImage(string $image): Image |
29 | { |
30 | if (str_starts_with($image, 'http')) { |
31 | return new Image([ |
32 | 'uri' => $image, |
33 | ]); |
34 | } |
35 | |
36 | return new Image([ |
37 | 'path' => $image, |
38 | ]); |
39 | } |
40 | |
41 | public function constructFullImage(array $image): Image |
42 | { |
43 | return new Image($image); |
44 | } |
45 | } |