OptionNotFoundException   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 15
c 1
b 0
f 1
dl 0
loc 36
ccs 15
cts 15
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B missingOptions() 0 28 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-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 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 7
    public static function missingOptions(RequiresConfig $factory, $currentDimension, ?string $configId) : self
31
    {
32 7
        $position = [];
33
34 7
        $dimensions = $factory->dimensions();
35
36 7
        if ($factory instanceof RequiresConfigId) {
37 4
            $dimensions[] = $configId;
38
        }
39
40 7
        foreach ($dimensions as $dimension) {
41 7
            $position[] = $dimension;
42
43 7
            if ($dimension === $currentDimension) {
44 7
                break;
45
            }
46
        }
47
48 7
        if ($factory instanceof RequiresConfigId && $configId === null && count($dimensions) === count($position)) {
49 3
            return new static(
50 3
                rtrim(
51 3
                    sprintf('The configuration "%s" needs a config id.', implode('.', $position)),
52 3
                    '.'
53
                )
54
            );
55
        }
56
57 4
        return new static(sprintf('No options set for configuration "%s"', implode('.', $position)));
58
    }
59
}
60