Passed
Push — master ( dc8e75...2bb448 )
by Caen
03:21 queued 15s
created

Files::getSourceFiles()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation\Facades;
6
7
use Hyde\Foundation\HydeKernel;
8
use Hyde\Foundation\Kernel\FileCollection;
9
use Hyde\Framework\Exceptions\FileNotFoundException;
10
use Hyde\Support\Filesystem\MediaFile;
11
use Hyde\Support\Filesystem\ProjectFile;
12
use Hyde\Support\Filesystem\SourceFile;
13
use Illuminate\Support\Facades\Facade;
14
15
/**
16
 * @mixin \Hyde\Foundation\Kernel\FileCollection
17
 */
18
class Files extends Facade
19
{
20
    public static function getFile(string $filePath): ProjectFile
21
    {
22
        return static::getFacadeRoot()->get($filePath) ?? throw new FileNotFoundException(message: "File [$filePath] not found in file collection");
23
    }
24
25
    /**
26
     * @param  class-string<\Hyde\Pages\Concerns\HydePage>|null  $pageClass
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\Hyde\Pages\Concerns\HydePage>|null at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\Hyde\Pages\Concerns\HydePage>|null.
Loading history...
27
     * @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile>
28
     */
29
    public static function getSourceFiles(?string $pageClass = null): FileCollection
30
    {
31
        return $pageClass ? static::getSourceFilesFor($pageClass) : static::getAllSourceFiles();
32
    }
33
34
    /**
35
     * @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...
36
     * @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile>
37
     */
38
    public static function getSourceFilesFor(string $pageClass): FileCollection
39
    {
40
        return static::getAllSourceFiles()->where(fn (SourceFile $file): bool => $file->model === $pageClass);
41
    }
42
43
    /** @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile> */
44
    public static function getAllSourceFiles(): FileCollection
45
    {
46
        return static::getFacadeRoot()->where(fn (ProjectFile $file): bool => $file instanceof SourceFile);
47
    }
48
49
    /** @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\MediaFile> */
50
    public static function getMediaFiles(): FileCollection
51
    {
52
        return static::getFacadeRoot()->where(fn (ProjectFile $file): bool => $file instanceof MediaFile);
53
    }
54
55
    /**  @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\ProjectFile> */
56
    public static function getFacadeRoot(): FileCollection
57
    {
58
        return HydeKernel::getInstance()->files();
59
    }
60
}
61