InvalidKeyException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A forKey() 0 10 2
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Collections\Exception;
11
12
use InvalidArgumentException;
13
use Exception;
14
15
/**
16
 * InvalidKeyException class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 */
20
class InvalidKeyException extends InvalidArgumentException
21
{
22
    /**
23
     * Creates an exception for an invalid key.
24
     *
25
     * @param mixed          $key
26
     * @param string         $message
27
     * @param Exception|null $cause
28
     *
29
     * @return InvalidKeyException
30
     */
31
    public static function forKey(
32
        $key,
33
        $message = 'Expected a key of type integer or string. Got: %s',
34
        Exception $cause = null
35
    ) {
36
        return new static(sprintf(
37
            $message,
38
            is_object($key) ? get_class($key) : gettype($key)
39
        ), 0, $cause);
40
    }
41
}
42