Passed
Push — master ( 2aaa83...8f0998 )
by Caen
03:24 queued 13s
created

SourceFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 8
Bugs 0 Features 1
Metric Value
eloc 7
c 8
b 0
f 1
dl 0
loc 29
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A withoutDirectoryPrefix() 0 4 1
A toArray() 0 4 1
A __construct() 0 4 1
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
    /**
25
     * @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...
26
     */
27
    public function __construct(string $path, string $pageClass = HydePage::class)
28
    {
29
        parent::__construct($path);
30
        $this->model = $pageClass;
0 ignored issues
show
Bug introduced by
The property model is declared read-only in Hyde\Support\Filesystem\SourceFile.
Loading history...
31
    }
32
33
    public function toArray(): array
34
    {
35
        return array_merge(parent::toArray(), [
36
            'model' => $this->model,
37
        ]);
38
    }
39
40
    public function withoutDirectoryPrefix(): string
41
    {
42
        // Works like basename, but keeps subdirectory names.
43
        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...
44
    }
45
}
46