Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
ProjectFile | |
100.00% |
11 / 11 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
make | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
toArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getAbsolutePath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContents | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getExtension | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Hyde\Support\Filesystem; |
6 | |
7 | use function basename; |
8 | |
9 | use Hyde\Facades\Filesystem; |
10 | use Hyde\Hyde; |
11 | use Hyde\Support\Concerns\Serializable; |
12 | use Hyde\Support\Contracts\SerializableContract; |
13 | |
14 | use function pathinfo; |
15 | |
16 | /** |
17 | * Filesystem abstraction for a file stored in the project. |
18 | */ |
19 | abstract class ProjectFile implements SerializableContract |
20 | { |
21 | use Serializable; |
22 | |
23 | /** |
24 | * @var string The path relative to the project root. |
25 | * |
26 | * @example `_pages/index.blade.php` |
27 | * @example `_media/logo.png` |
28 | */ |
29 | public readonly string $path; |
30 | |
31 | public static function make(string $path): static |
32 | { |
33 | return new static($path); |
34 | } |
35 | |
36 | public function __construct(string $path) |
37 | { |
38 | $this->path = Hyde::pathToRelative($path); |
39 | } |
40 | |
41 | /** |
42 | * @return array{name: string, path: string} |
43 | */ |
44 | public function toArray(): array |
45 | { |
46 | return [ |
47 | 'name' => $this->getName(), |
48 | 'path' => $this->getPath(), |
49 | ]; |
50 | } |
51 | |
52 | public function getName(): string |
53 | { |
54 | return basename($this->path); |
55 | } |
56 | |
57 | public function getPath(): string |
58 | { |
59 | return $this->path; |
60 | } |
61 | |
62 | public function getAbsolutePath(): string |
63 | { |
64 | return Hyde::path($this->path); |
65 | } |
66 | |
67 | public function getContents(): string |
68 | { |
69 | return Filesystem::getContents($this->path); |
70 | } |
71 | |
72 | public function getExtension(): string |
73 | { |
74 | return pathinfo($this->getAbsolutePath(), PATHINFO_EXTENSION); |
75 | } |
76 | } |