Completed
Push — master ( 33cd17...4bddcc )
by Arnold
02:40
created

ResolveException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 13 4
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
     * @noinspection PhpTooManyParametersInspection
16
     *
17
     * @param string   $msg
18
     * @param string   $path
19
     * @param string   $delimiter
20
     * @param string[] $index
21
     * @param string   $key
22
     * @throws ResolveException
23
     */
24 30
    public static function create(
25
        string $msg,
26
        string $path,
27
        string $delimiter,
28
        array $index,
29
        ?string $key = null,
30
        ?\Throwable $previous = null
31
    ): ResolveException {
32 30
        $len = ($index !== [] ? \strlen($delimiter) + \strlen(\join($delimiter, $index)) : 0)
33 30
            + ($key !== null ? \strlen($delimiter) + \strlen($key) : 0);
34 30
        $invalidPath = $len > 0 ? \substr(\rtrim($path, $delimiter), 0, -1 * $len) : $path;
35
36 30
        return new ResolveException(sprintf($msg, $invalidPath), 0, $previous);
37
    }
38
}
39