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

OptionNotFoundException::missingOptions()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 7

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 29
rs 6.7272
ccs 14
cts 14
cp 1
cc 7
eloc 15
nc 12
nop 3
crap 7
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 Interop\Config\RequiresConfig;
13
use Interop\Config\RequiresConfigId;
14
15
/**
16
 * Option not found exception
17
 *
18
 * Use this exception if an option was not found in the config
19
 */
20
class OptionNotFoundException extends OutOfBoundsException
21
{
22
    /**
23
     * @param RequiresConfig $factory
24
     * @param mixed $currentDimension Current configuration key
25
     * @param string $configId
26
     * @return InvalidArgumentException
27
     */
28 5
    public static function missingOptions(RequiresConfig $factory, $currentDimension, $configId)
29
    {
30 5
        $position = [];
31
32 5
        $dimensions = $factory->dimensions();
33
34 5
        if ($factory instanceof RequiresConfigId) {
35 2
            $dimensions[] = $configId;
36
        }
37
38 5
        foreach ($dimensions as $dimension) {
39 5
            $position[] = $dimension;
40
41 5
            if ($dimension === $currentDimension) {
42 5
                break;
43
            }
44
        }
45
46 5
        if ($factory instanceof RequiresConfigId && $configId === null && count($dimensions) === count($position)) {
47 1
            return new static(
48
                rtrim(
49 1
                    sprintf('The configuration "%s" needs a config id.', implode('.', $position)),
50 1
                    '.'
51
                )
52
            );
53
        }
54
55 4
        return new static(sprintf('No options set for configuration "%s"', implode('.', $position)));
56
    }
57
}
58