|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Support\Filesystem; |
|
6
|
|
|
|
|
7
|
|
|
use function basename; |
|
8
|
|
|
use Hyde\Facades\Filesystem; |
|
9
|
|
|
use Hyde\Hyde; |
|
10
|
|
|
use Hyde\Support\Concerns\Serializable; |
|
11
|
|
|
use Hyde\Support\Contracts\SerializableContract; |
|
12
|
|
|
use function pathinfo; |
|
13
|
|
|
use Stringable; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Filesystem abstraction for a file stored in the project. |
|
17
|
|
|
* |
|
18
|
|
|
* @see \Hyde\Framework\Testing\Feature\FileTest |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class ProjectFile implements SerializableContract, Stringable |
|
21
|
|
|
{ |
|
22
|
|
|
use Serializable; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var string The path relative to the project root. |
|
26
|
|
|
* |
|
27
|
|
|
* @example `_pages/index.blade.php` |
|
28
|
|
|
* @example `_media/logo.png` |
|
29
|
|
|
*/ |
|
30
|
|
|
public readonly string $path; |
|
31
|
|
|
|
|
32
|
|
|
public static function make(string $path, ...$args): static |
|
33
|
|
|
{ |
|
34
|
|
|
return new static($path, ...$args); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function __construct(string $path) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->path = Hyde::pathToRelative($path); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function __toString(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->path; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function toArray(): array |
|
48
|
|
|
{ |
|
49
|
|
|
return [ |
|
|
|
|
|
|
50
|
|
|
'name' => $this->getName(), |
|
51
|
|
|
'path' => $this->getPath(), |
|
52
|
|
|
]; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getName(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return basename($this->path); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getPath(): string |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->path; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getAbsolutePath(): string |
|
66
|
|
|
{ |
|
67
|
|
|
return Hyde::path($this->path); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getContents(): string |
|
71
|
|
|
{ |
|
72
|
|
|
return Filesystem::getContents($this->path); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getExtension(): string |
|
76
|
|
|
{ |
|
77
|
|
|
return pathinfo($this->getAbsolutePath(), PATHINFO_EXTENSION); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.