InvalidKeyException::forKey()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 1
nop 2
crap 2
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 is invalid.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class InvalidKeyException extends RuntimeException
25
{
26
    /**
27
     * Creates an exception for an invalid key.
28
     *
29
     * @param mixed          $key   The invalid key.
30
     * @param Exception|null $cause The exception that caused this exception.
31
     *
32
     * @return static The created exception.
33
     */
34 154 View Code Duplication
    public static function forKey($key, Exception $cause = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36 154
        return new static(sprintf(
37 154
            'Expected a key of type integer or string. Got: %s',
38 154
            is_object($key) ? get_class($key) : gettype($key)
39 154
        ), 0, $cause);
40
    }
41
}
42