ExceptionHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidArrayDefinitionKey() 0 6 1
A incorrectArrayDefinitionConstructorArguments() 0 6 1
A incorrectArrayDefinitionMethodArguments() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Definitions\Helpers;
6
7
use Yiisoft\Definitions\Exception\InvalidConfigException;
8
9
/**
10
 * @internal
11
 */
12
final class ExceptionHelper
13
{
14 2
    public static function invalidArrayDefinitionKey(int|string $key): InvalidConfigException
15
    {
16 2
        return new InvalidConfigException(
17 2
            sprintf(
18 2
                'Invalid definition: invalid key in array definition. Only string keys are allowed, got %d.',
19 2
                $key,
20 2
            ),
21 2
        );
22
    }
23
24 3
    public static function incorrectArrayDefinitionConstructorArguments(mixed $value): InvalidConfigException
25
    {
26 3
        return new InvalidConfigException(
27 3
            sprintf(
28 3
                'Invalid definition: incorrect constructor arguments. Expected array, got %s.',
29 3
                get_debug_type($value)
30 3
            )
31 3
        );
32
    }
33
34 3
    public static function incorrectArrayDefinitionMethodArguments(string $key, mixed $value): InvalidConfigException
35
    {
36 3
        return new InvalidConfigException(
37 3
            sprintf(
38 3
                'Invalid definition: incorrect method "%s" arguments. Expected array, got "%s". ' .
39 3
                'Probably you should wrap them into square brackets.',
40 3
                $key,
41 3
                get_debug_type($value),
42 3
            )
43 3
        );
44
    }
45
}
46