Completed
Pull Request — master (#21)
by Bernhard
10:43
created

UnsupportedValueException::forValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 4
crap 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 an unsupported value is stored in a key-value store.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class UnsupportedValueException extends RuntimeException
25
{
26
    /**
27
     * Creates a new exception for the given value type.
28
     *
29
     * @param string         $type  The name of the unsupported type.
30
     * @param KeyValueStore  $store The store that does not support the type.
31
     * @param int            $code  The exception code.
32
     * @param Exception|null $cause The exception that caused this exception.
33
     *
34
     * @return static The new exception.
35
     */
36 8
    public static function forType($type, KeyValueStore $store, $code = 0, Exception $cause = null)
37
    {
38 8
        return new static(sprintf(
39 8
            'Values of type %s are not supported by %s.',
40
            $type,
41
            get_class($store)
42
        ), $code, $cause);
43
    }
44
45
    /**
46
     * Creates a new exception for the given value.
47
     *
48
     * @param string         $value The unsupported value.
49
     * @param KeyValueStore  $store The store that does not support the type.
50
     * @param int            $code  The exception code.
51
     * @param Exception|null $cause The exception that caused this exception.
52
     *
53
     * @return static The new exception.
54
     */
55 22 View Code Duplication
    public static function forValue($value, KeyValueStore $store, $code = 0, 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...
56
    {
57 22
        return new static(sprintf(
58 22
            'Values of type %s are not supported by %s.',
59
            gettype($value),
60
            get_class($store)
61
        ), $code, $cause);
62
    }
63
}
64