NoSuchKeyException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 2
c 3
b 1
f 1
lcom 0
cbo 0
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A forKey() 0 7 1
A forKeys() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the webmozart/key-value-store package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\KeyValueStore\Api;
13
14
use Exception;
15
use RuntimeException;
16
17
/**
18
 * Thrown when a key was not found in the store.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class NoSuchKeyException extends RuntimeException
25
{
26
    /**
27
     * Creates an exception for a key that was not found.
28
     *
29
     * @param string|int     $key   The key that was not found.
30
     * @param Exception|null $cause The exception that caused this exception.
31
     *
32
     * @return static The created exception.
33
     */
34 15
    public static function forKey($key, Exception $cause = null)
35
    {
36 15
        return new static(sprintf(
37 15
            'The key "%s" does not exist.',
38
            $key
39 15
        ), 0, $cause);
40
    }
41
42
    /**
43
     * Creates an exception for multiple keys that were not found.
44
     *
45
     * @param array[]        $keys  The keys that were not found.
46
     * @param Exception|null $cause The exception that caused this exception.
47
     *
48
     * @return static The created exception.
49
     */
50 11
    public static function forKeys(array $keys, Exception $cause = null)
51
    {
52 11
        return new static(sprintf(
53 11
            'The keys "%s" does not exist.',
54 11
            implode('", "', $keys)
55 11
        ), 0, $cause);
56
    }
57
}
58