Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| InvalidArgumentException | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| forNonStringKeyWithValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| forUnreadableDirectory | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of php-fast-forward/config. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @link https://github.com/php-fast-forward/config |
| 12 | * @copyright Copyright (c) 2025 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 13 | * @license https://opensource.org/licenses/MIT MIT License |
| 14 | */ |
| 15 | |
| 16 | namespace FastForward\Config\Exception; |
| 17 | |
| 18 | /** |
| 19 | * Class InvalidArgumentException. |
| 20 | * |
| 21 | * Specialized exception for handling invalid arguments within the configuration context. |
| 22 | * This class SHALL be used to provide meaningful errors when invalid data is passed |
| 23 | * to configuration components. |
| 24 | */ |
| 25 | final class InvalidArgumentException extends \InvalidArgumentException |
| 26 | { |
| 27 | /** |
| 28 | * Thrown when the key is not a string but a value is provided. |
| 29 | * |
| 30 | * @return self the exception indicating the key must be a string |
| 31 | */ |
| 32 | public static function forNonStringKeyWithValue(): self |
| 33 | { |
| 34 | return new self('The key must be a string when a value is provided.'); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Thrown when a given directory does not exist or is not readable. |
| 39 | * |
| 40 | * @param string $directory the path to the invalid directory |
| 41 | * |
| 42 | * @return self the exception indicating an invalid or unreadable directory |
| 43 | */ |
| 44 | public static function forUnreadableDirectory(string $directory): self |
| 45 | { |
| 46 | return new self(\sprintf( |
| 47 | 'The directory "%s" does not exist or is not readable.', |
| 48 | $directory, |
| 49 | )); |
| 50 | } |
| 51 | } |