Completed
Push — master ( bca71a...3af5ad )
by Sandro
06:14 queued 02:11
created

UnexpectedValueException::invalidOptions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 19
rs 9.4285
ccs 8
cts 9
cp 0.8889
cc 3
eloc 11
nc 3
nop 2
crap 3.0123
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-2016 Sandro Keil
7
 * @license   http://github.com/sandrokeil/interop-config/blob/master/LICENSE.md New BSD License
8
 */
9
10
namespace Interop\Config\Exception;
11
12
use UnexpectedValueException as PhpUnexpectedValueException;
13
14
/**
15
 * UnexpectedValueException exception
16
 *
17
 * Use this exception if a value is outside a set of values.
18
 */
19
class UnexpectedValueException extends PhpUnexpectedValueException implements ExceptionInterface
20
{
21
    /**
22
     * @param array|\ArrayAccess $dimensions
23
     * @param mixed $currentDimension Current configuration key
24
     * @return UnexpectedValueException
25
     */
26 1
    public static function invalidOptions($dimensions, $currentDimension = null)
27
    {
28 1
        $position = [];
29
30 1
        foreach ($dimensions as $dimension) {
31 1
            if ($dimension === $currentDimension) {
32
                break;
33
            }
34 1
            $position[] = $dimension;
35
        }
36
37 1
        return new static(
38
            sprintf(
39
                'Configuration must either be of type "array" or implement "\ArrayAccess". ' .
40 1
                'Configuration position is "%s"',
41 1
                rtrim(implode('.', $position), '.')
42
            )
43
        );
44
    }
45
}
46