Passed
Push — master ( f4f5f5...69e5ba )
by Caen
02:58 queued 12s
created

PublishableView::toArray()   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
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Framework\Features\Templates;
6
7
use Hyde\Hyde;
8
9
abstract class PublishableView implements PublishableContract
10
{
11
    protected static string $title;
12
    protected static string $desc;
13
    protected static string $path;
14
    protected static ?string $outputPath;
15
16
    public static function publish(bool $force = false): bool
17
    {
18
        $path = static::getOutputPath();
19
20
        if (file_exists($path) && ! $force) {
21
            return false;
22
        }
23
24
        return copy(static::getSourcePath(), $path);
25
    }
26
27
    public static function getTitle(): string
28
    {
29
        return static::$title;
30
    }
31
32
    public static function getDescription(): string
33
    {
34
        return static::$desc;
35
    }
36
37
    public static function getOutputPath(): string
38
    {
39
        // All publishable views at this time are Blade templates so to
40
        // reduce premature complexity we just use the Blade paths here.
41
42
        return Hyde::getBladePagePath(static::$outputPath ?? static::$path);
43
    }
44
45
    protected static function getSourcePath(): string
46
    {
47
        return Hyde::vendorPath(static::$path);
48
    }
49
50
    public static function toArray(): array
51
    {
52
        return [
53
            'name' => static::getTitle(),
54
            'description' => static::getDescription(),
55
        ];
56
    }
57
}
58