ResolveException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\DotKey;
6
7
/**
8
 * Exception throw if path can't be resolved.
9
 */
10
class ResolveException extends \RuntimeException
11
{
12
    /**
13
     * Create a ResolveException, filling out %s with invalid path.
14
     *
15
     * @param string   $msg
16
     * @param string   $path
17
     * @param string   $delimiter
18
     * @param string[] $index
19
     * @throws ResolveException
20
     */
21 30
    public static function create(
22
        string $msg,
23
        string $path,
24
        string $delimiter,
25
        array $index,
26
        ?\Throwable $previous = null
27
    ): ResolveException {
28 30
        $len = ($index !== [] ? \strlen($delimiter) + \strlen(\join($delimiter, $index)) : 0);
29 30
        $invalidPath = $len > 0 ? \substr(\rtrim($path, $delimiter), 0, -1 * $len) : $path;
30
31 30
        return new ResolveException(sprintf($msg, $invalidPath), 0, $previous);
32
    }
33
}
34