Passed
Push — master ( a9db05...32ab90 )
by Caen
03:20 queued 13s
created

Files::getMediaFiles()   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
c 1
b 0
f 0
nc 1
nop 0
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\ProjectFile;
11
use Hyde\Support\Filesystem\SourceFile;
12
use Illuminate\Support\Facades\Facade;
13
14
/**
15
 * @mixin \Hyde\Foundation\Kernel\FileCollection
16
 */
17
class Files extends Facade
18
{
19
    public static function getFile(string $filePath): ProjectFile
20
    {
21
        return static::getFacadeRoot()->get($filePath) ?? throw new FileNotFoundException(message: "File [$filePath] not found in file collection");
22
    }
23
24
    /**
25
     * @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...
26
     * @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile>
27
     */
28
    public static function getSourceFiles(?string $pageClass = null): FileCollection
29
    {
30
        return $pageClass ? static::getSourceFilesFor($pageClass) : static::getAllSourceFiles();
31
    }
32
33
    /**
34
     * @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...
35
     * @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile>
36
     */
37
    public static function getSourceFilesFor(string $pageClass): FileCollection
38
    {
39
        return static::getAllSourceFiles()->where(fn (SourceFile $file): bool => $file->model === $pageClass);
40
    }
41
42
    /** @return \Hyde\Foundation\Kernel\FileCollection<\Hyde\Support\Filesystem\SourceFile> */
43
    public static function getAllSourceFiles(): FileCollection
44
    {
45
        return static::getFacadeRoot()->where(fn (ProjectFile $file): bool => $file instanceof SourceFile);
46
    }
47
48
    /**  @return \Hyde\Foundation\Kernel\FileCollection<string, \Hyde\Support\Filesystem\ProjectFile> */
49
    public static function getFacadeRoot(): FileCollection
50
    {
51
        return HydeKernel::getInstance()->files();
52
    }
53
}
54