Passed
Push — main ( 862db6...ec7436 )
by Colin
01:43
created

InvalidConfigurationException::forConfigOption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 3
crap 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
/**
17
 * @psalm-immutable
18
 */
19
class InvalidConfigurationException extends \UnexpectedValueException implements ConfigurationExceptionInterface
20
{
21
    /**
22
     * @param string  $option      Name/path of the option
23
     * @param mixed   $valueGiven  The invalid option that was provided
24
     * @param ?string $description Additional text describing the issue (optional)
25
     */
26 9
    public static function forConfigOption(string $option, $valueGiven, ?string $description = null): self
27
    {
28 9
        $message = \sprintf('Invalid config option for "%s": %s', $option, self::getDebugValue($valueGiven));
29 9
        if ($description !== null) {
30 3
            $message .= \sprintf(' (%s)', $description);
31
        }
32
33 9
        return new self($message);
34
    }
35
36
    /**
37
     * @param mixed $value
38
     */
39 9
    private static function getDebugValue($value): string
40
    {
41 9
        if (\is_object($value)) {
42 3
            return \get_class($value);
43
        }
44
45 6
        return \print_r($value, true);
46
    }
47
}
48