ImmutableSettingOverrideException::build()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 15
ccs 7
cts 7
cp 1
crap 2
rs 10
1
<?php
2
3
/**
4
 * Settings Manager
5
 *
6
 * @license http://opensource.org/licenses/MIT
7
 * @link https://github.com/caseyamcl/settings-manager
8
 * @package caseyamcl/settings-manager
9
 * @author Casey McLaughlin <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 *
14
 *  ------------------------------------------------------------------
15
 */
16
17
declare(strict_types=1);
18
19
namespace SettingsManager\Exception;
20
21
use LogicException;
22
use Throwable;
23
24
/**
25
 * Immutable setting override exception
26
 *
27
 * Thrown when an implementing library attempts to set an immutable setting
28
 * that has already been set.
29
 *
30
 * @author Casey McLaughlin <[email protected]>
31
 */
32
class ImmutableSettingOverrideException extends LogicException implements SettingException
33
{
34
    /**
35
     * @param string $settingName
36
     * @param string $provider
37
     * @param string $originalProvider
38
     * @param Throwable|null $prior
39
     * @return ImmutableSettingOverrideException
40
     */
41 3
    public static function build(
42
        string $settingName,
43
        string $provider,
44
        string $originalProvider,
45
        Throwable $prior = null
46
    ) {
47
48 3
        $msg = sprintf(
49 3
            'Setting name collision: %s (attempting to load from %s; already loaded from %s)',
50 2
            $settingName,
51 2
            $provider,
52 2
            $originalProvider
53
        );
54
55 3
        return new static($msg, $prior ? $prior->getCode() : 0, $prior);
56
    }
57
}
58