UnexpectedValueException::invalidOptions()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 16
ccs 9
cts 10
cp 0.9
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.009
1
<?php
2
/**
3
 * Sandro Keil (https://sandro-keil.de)
4
 *
5
 * @link      http://github.com/sandrokeil/interop-config for the canonical source repository
6
 * @copyright Copyright (c) 2015-2020 Sandro Keil
7
 * @license   http://github.com/sandrokeil/interop-config/blob/master/LICENSE.md New BSD License
8
 */
9
10
declare(strict_types = 1);
11
12
namespace Interop\Config\Exception;
13
14
use UnexpectedValueException as PhpUnexpectedValueException;
15
16
/**
17
 * UnexpectedValueException exception
18
 *
19
 * Use this exception if a value is outside a set of values.
20
 */
21
class UnexpectedValueException extends PhpUnexpectedValueException implements ExceptionInterface
22
{
23
    /**
24
     * @param iterable $dimensions
25
     * @param mixed $currentDimension Current configuration key
26
     * @return UnexpectedValueException
27
     */
28 1
    public static function invalidOptions(iterable $dimensions, $currentDimension = null) : self
29
    {
30 1
        $position = [];
31
32 1
        foreach ($dimensions as $dimension) {
33 1
            if ($dimension === $currentDimension) {
34
                break;
35
            }
36 1
            $position[] = $dimension;
37
        }
38
39 1
        return new static(
40 1
            sprintf(
41
                'Configuration must either be of type "array" or implement "\ArrayAccess". ' .
42 1
                'Configuration position is "%s"',
43 1
                rtrim(implode('.', $position), '.')
44
            )
45
        );
46
    }
47
}
48