Passed
Push — master ( 320aa5...c46ad6 )
by Caen
03:10 queued 12s
created

SourceFile::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Support\Filesystem;
6
7
use Hyde\Pages\Concerns\HydePage;
8
use Illuminate\Support\Str;
9
10
/**
11
 * File abstraction for a project source file.
12
 *
13
 * @see \Hyde\Foundation\FileCollection
14
 */
15
class SourceFile extends ProjectFile
16
{
17
    /**
18
     * The associated page class string.
19
     *
20
     * @var class-string<\Hyde\Pages\Concerns\HydePage>
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\Hyde\Pages\Concerns\HydePage> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\Hyde\Pages\Concerns\HydePage>.
Loading history...
21
     */
22
    public readonly string $model;
23
24
    /** @param  class-string<\Hyde\Pages\Concerns\HydePage>  $pageClass */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\Hyde\Pages\Concerns\HydePage> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\Hyde\Pages\Concerns\HydePage>.
Loading history...
25
    public static function make(string $path, string $pageClass = HydePage::class): static
26
    {
27
        return new static($path, $pageClass);
28
    }
29
30
    /** @param  class-string<\Hyde\Pages\Concerns\HydePage>  $pageClass */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\Hyde\Pages\Concerns\HydePage> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\Hyde\Pages\Concerns\HydePage>.
Loading history...
31
    public function __construct(string $path, string $pageClass = HydePage::class)
32
    {
33
        parent::__construct($path);
34
        $this->model = $pageClass;
0 ignored issues
show
Bug introduced by
The property model is declared read-only in Hyde\Support\Filesystem\SourceFile.
Loading history...
35
    }
36
37
    public function toArray(): array
38
    {
39
        return array_merge(parent::toArray(), [
40
            'model' => $this->model,
41
        ]);
42
    }
43
44
    public function withoutDirectoryPrefix(): string
45
    {
46
        // Works like basename, but keeps subdirectory names.
47
        return Str::after($this->path, $this->model::$sourceDirectory.'/');
0 ignored issues
show
Bug introduced by
The property sourceDirectory does not exist on string.
Loading history...
48
    }
49
}
50