Completed
Push — master ( 3af5ad...f60e47 )
by Sandro
10s
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
declare(strict_types = 1);
11
12
namespace Interop\Config\Exception;
13
14
use Interop\Config\RequiresConfig;
15
use Interop\Config\RequiresConfigId;
16
17
/**
18
 * Option not found exception
19
 *
20
 * Use this exception if an option was not found in the config
21
 */
22
class OptionNotFoundException extends OutOfBoundsException
23
{
24
    /**
25
     * @param RequiresConfig $factory
26
     * @param mixed $currentDimension Current configuration key
27
     * @param string $configId
28
     * @return OptionNotFoundException
29
     */
30 6
    public static function missingOptions(RequiresConfig $factory, $currentDimension, ?string $configId) : self
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '?', expecting T_VARIABLE
Loading history...
31
    {
32 6
        $position = [];
33
34 6
        $dimensions = $factory->dimensions();
35
36 6
        if ($factory instanceof RequiresConfigId) {
37 3
            $dimensions[] = $configId;
38
        }
39
40 6
        foreach ($dimensions as $dimension) {
41 6
            $position[] = $dimension;
42
43 6
            if ($dimension === $currentDimension) {
44 6
                break;
45
            }
46
        }
47
48 6
        if ($factory instanceof RequiresConfigId && $configId === null && count($dimensions) === count($position)) {
49 2
            return new static(
50
                rtrim(
51 2
                    sprintf('The configuration "%s" needs a config id.', implode('.', $position)),
52 2
                    '.'
53
                )
54
            );
55
        }
56
57 4
        return new static(sprintf('No options set for configuration "%s"', implode('.', $position)));
58
    }
59
}
60