Passed
Push — master ( baa861...039f87 )
by Caen
04:23 queued 11s
created

FrontMatter::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework\Models;
4
5
use Hyde\Framework\Actions\ConvertsArrayToFrontMatter;
6
use Illuminate\Contracts\Support\Arrayable;
7
use Illuminate\Support\Arr;
8
9
/**
10
 * @see \Hyde\Framework\Testing\Unit\FrontMatterModelTest
11
 */
12
class FrontMatter implements Arrayable
13
{
14
    public array $matter;
15
16
    public function __construct(array $matter = [])
17
    {
18
        $this->matter = $matter;
19
    }
20
21
    public function __toString(): string
22
    {
23
        return (new ConvertsArrayToFrontMatter())->execute($this->matter);
24
    }
25
26
    public function __get(string $key): mixed
27
    {
28
        return $this->get($key);
29
    }
30
31
    public function get(string $key = null, mixed $default = null): mixed
32
    {
33
        if ($key) {
34
            return Arr::get($this->matter, $key, $default);
35
        }
36
37
        return $this->matter;
38
    }
39
40
    public function toArray(): array
41
    {
42
        return $this->matter;
43
    }
44
45
    public static function fromArray(array $matter): static
46
    {
47
        return new static($matter);
48
    }
49
}
50