InvalidKeyException::forKey()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 1
nop 3
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