Lines
83.33%
5 / 6
Methods
66.66%
2 / 3
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 4 / 4 | 100.00% | 1 / 1 | 4 | ||
| resolveWithin | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| __toString | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | ||
| 10 | final readonly class ProjectDirectory implements Stringable | |
| 11 | { | |
| 12 | public string $value; | |
| 13 | ||
| 14 | /** @throws ConfigurationException */ | |
| 15 | public function __construct(string $value) | |
| 16 | { | |
| 17 | $directory = rtrim($value, '/'); | |
| 18 | ||
| 19 | // Restricted to the project: the result goes to a writer that deletes files. | |
| 20 | if ($directory === '' || str_starts_with($directory, '/') || \in_array('..', explode('/', $directory), true)) { | |
| 21 | throw ConfigurationException::valueInvalid($value, 'a path inside the project, such as "generated"'); | |
| 22 | } | |
| 23 | ||
| 24 | $this->value = $directory; | |
| 25 | } | |
| 26 | ||
| 27 | public function resolveWithin(string $projectRoot): string | |
| 28 | { | |
| 29 | return $projectRoot . '/' . $this->value; | |
| 30 | } | |
| 31 | ||
| 32 | public function __toString(): string | |
| 33 | { | |
| 34 | return $this->value; | |
| 35 | } | |
| 36 | } |