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

OptionNotFoundException   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 7
c 4
b 0
f 2
lcom 0
cbo 2
dl 0
loc 38
rs 10
ccs 14
cts 14
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C missingOptions() 0 29 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