Completed
Push — master ( deae46...6c5f37 )
by Colin
01:01
created

InvalidOptionException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 32
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forConfigOption() 0 4 1
A forParameter() 0 4 1
A getDebugValue() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark 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\CommonMark\Exception;
15
16
final class InvalidOptionException extends \UnexpectedValueException
17
{
18
    /**
19
     * @param string $option     Name/path of the option
20
     * @param mixed  $valueGiven The invalid option that was provided
21
     */
22
    public static function forConfigOption(string $option, $valueGiven): self
23
    {
24
        return new self(\sprintf('Invalid config option for "%s": %s', $option, self::getDebugValue($valueGiven)));
25
    }
26
27
    /**
28
     * @param string $option     Description of the option
29
     * @param mixed  $valueGiven The invalid option that was provided
30
     */
31
    public static function forParameter(string $option, $valueGiven): self
32
    {
33
        return new self(\sprintf('Invalid %s: %s', $option, self::getDebugValue($valueGiven)));
34
    }
35
36
    /**
37
     * @param mixed $value
38
     */
39
    private static function getDebugValue($value): string
40
    {
41
        if (\is_object($value)) {
42
            return \get_class($value);
43
        }
44
45
        return \print_r($value, true);
46
    }
47
}
48