InvalidConfigurationException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 2
b 0
f 0
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forConfigOption() 0 8 2
A getDebugValue() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/config package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\Config\Exception;
15
16
class InvalidConfigurationException extends \UnexpectedValueException implements ConfigurationExceptionInterface
17
{
18
    /**
19
     * @param string  $option      Name/path of the option
20
     * @param mixed   $valueGiven  The invalid option that was provided
21
     * @param ?string $description Additional text describing the issue (optional)
22
     */
23 9
    public static function forConfigOption(string $option, $valueGiven, ?string $description = null): self
24
    {
25 9
        $message = \sprintf('Invalid config option for "%s": %s', $option, self::getDebugValue($valueGiven));
26 9
        if ($description !== null) {
27 3
            $message .= \sprintf(' (%s)', $description);
28
        }
29
30 9
        return new self($message);
31
    }
32
33
    /**
34
     * @param mixed $value
35
     *
36
     * @psalm-pure
37
     */
38 9
    private static function getDebugValue($value): string
39
    {
40 9
        if (\is_object($value)) {
41 3
            return \get_class($value);
42
        }
43
44
        // @phpstan-ignore possiblyImpure.functionCall
45 6
        return \print_r($value, true);
0 ignored issues
show
Bug Best Practice introduced by
The expression return print_r($value, true) could return the type true which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
46
    }
47
}
48