Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidArgumentException
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
6 / 6
6
100.00% covered (success)
100.00%
1 / 1
 forEmptyPath
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forNonStringKeyWithValue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forUnreadableDirectory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forUnreadableFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forUnwritableFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 forInvalidConfigFile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(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 * @copyright Copyright (c) 2025-2026 Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
12 * @license   https://opensource.org/licenses/MIT MIT License
13 *
14 * @see       https://github.com/php-fast-forward/config
15 * @see       https://github.com/php-fast-forward
16 * @see       https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Config\Exception;
20
21/**
22 * Class InvalidArgumentException.
23 *
24 * Specialized exception for handling invalid arguments within the configuration context.
25 * This class SHALL be used to provide meaningful errors when invalid data is passed
26 * to configuration components.
27 */
28 class InvalidArgumentException extends \InvalidArgumentException
29{
30    /**
31     * Thrown when a configuration lookup path is empty.
32     *
33     * @return self the exception indicating the path cannot be empty
34     */
35    public static function forEmptyPath(): self
36    {
37        return new self('Path cannot be an empty string');
38    }
39
40    /**
41     * Thrown when the key is not a string but a value is provided.
42     *
43     * @return self the exception indicating the key must be a string
44     */
45    public static function forNonStringKeyWithValue(): self
46    {
47        return new self('The key must be a string when a value is provided.');
48    }
49
50    /**
51     * Thrown when a given directory does not exist or is not readable.
52     *
53     * @param string $directory the path to the invalid directory
54     *
55     * @return self the exception indicating an invalid or unreadable directory
56     */
57    public static function forUnreadableDirectory(string $directory): self
58    {
59        return new self(\sprintf('The directory "%s" does not exist or is not readable.', $directory));
60    }
61
62    /**
63     * Thrown when a given file does not exist or is not readable.
64     *
65     * @param string $file the path to the invalid file
66     *
67     * @return self the exception indicating an invalid or unreadable file
68     */
69    public static function forUnreadableFile(string $file): self
70    {
71        return new self(\sprintf('The file "%s" does not exist or is not readable.', $file));
72    }
73
74    /**
75     * Thrown when a configuration file is not writable.
76     *
77     * @param string $file the path to the unwritable file
78     *
79     * @return self the exception indicating an unwritable file
80     */
81    public static function forUnwritableFile(string $file): self
82    {
83        return new self(\sprintf('The file "%s" is not writable.', $file));
84    }
85
86    /**
87     * Thrown when a configuration file does not return an array.
88     *
89     * @param string $file the path to the configuration file
90     *
91     * @return self the exception indicating an invalid configuration file
92     */
93    public static function forInvalidConfigFile(string $file): self
94    {
95        return new self(\sprintf('The configuration file "%s" must return an array.', $file));
96    }
97}