Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
InvalidArgumentException
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
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 the key is not a string but a value is provided.
32     *
33     * @return self the exception indicating the key must be a string
34     */
35    public static function forNonStringKeyWithValue(): self
36    {
37        return new self('The key must be a string when a value is provided.');
38    }
39
40    /**
41     * Thrown when a given directory does not exist or is not readable.
42     *
43     * @param string $directory the path to the invalid directory
44     *
45     * @return self the exception indicating an invalid or unreadable directory
46     */
47    public static function forUnreadableDirectory(string $directory): self
48    {
49        return new self(\sprintf('The directory "%s" does not exist or is not readable.', $directory));
50    }
51
52    /**
53     * Thrown when a given file does not exist or is not readable.
54     *
55     * @param string $file the path to the invalid file
56     *
57     * @return self the exception indicating an invalid or unreadable file
58     */
59    public static function forUnreadableFile(string $file): self
60    {
61        return new self(\sprintf('The file "%s" does not exist or is not readable.', $file));
62    }
63
64    /**
65     * Thrown when a configuration file is not writable.
66     *
67     * @param string $file the path to the unwritable file
68     *
69     * @return self the exception indicating an unwritable file
70     */
71    public static function forUnwritableFile(string $file): self
72    {
73        return new self(\sprintf('The file "%s" is not writable.', $file));
74    }
75
76    /**
77     * Thrown when a configuration file does not return an array.
78     *
79     * @param string $file the path to the configuration file
80     *
81     * @return self the exception indicating an invalid configuration file
82     */
83    public static function forInvalidConfigFile(string $file): self
84    {
85        return new self(\sprintf('The configuration file "%s" must return an array.', $file));
86    }
87}
88