Completed
Push — latest ( 609def...dcbb7e )
by Colin
14s queued 11s
created

InvalidOptionException   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 9
c 1
b 0
f 1
dl 0
loc 36
ccs 8
cts 11
cp 0.7272
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A forParameter() 0 3 1
A getDebugValue() 0 7 2
A forConfigOption() 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
     * @param ?string $description Additional text describing the issue (optional)
22
     */
23 3
    public static function forConfigOption(string $option, $valueGiven, ?string $description = null): self
24
    {
25 3
        $message = \sprintf('Invalid config option for "%s": %s', $option, self::getDebugValue($valueGiven));
26 3
        if ($description !== null) {
27 3
            $message .= \sprintf(' (%s)', $description);
28
        }
29
30 3
        return new self($message);
31
    }
32
33
    /**
34
     * @param string $option     Description of the option
35
     * @param mixed  $valueGiven The invalid option that was provided
36
     */
37
    public static function forParameter(string $option, $valueGiven): self
38
    {
39
        return new self(\sprintf('Invalid %s: %s', $option, self::getDebugValue($valueGiven)));
40
    }
41
42
    /**
43
     * @param mixed $value
44
     */
45 3
    private static function getDebugValue($value): string
46
    {
47 3
        if (\is_object($value)) {
48
            return \get_class($value);
49
        }
50
51 3
        return \print_r($value, true);
52
    }
53
}
54