Code Duplication    Length = 38-38 lines in 2 locations

src/Api/SerializationFailedException.php 1 location

@@ 24-61 (lines=38) @@
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class SerializationFailedException extends RuntimeException
25
{
26
    /**
27
     * Creates a new exception for the given value.
28
     *
29
     * @param mixed     $value  The value that could not be serialized.
30
     * @param string    $reason The reason why the value could not be
31
     *                          unserialized.
32
     * @param int       $code   The exception code.
33
     * @param Exception $cause  The exception that caused this exception.
34
     *
35
     * @return static The new exception.
36
     */
37
    public static function forValue($value, $reason = '', $code = 0, Exception $cause = null)
38
    {
39
        return self::forType(is_object($value) ? get_class($value) : gettype($value), $reason, $code, $cause);
40
    }
41
42
    /**
43
     * Creates a new exception for the given value type.
44
     *
45
     * @param string    $type   The type that could not be serialized.
46
     * @param string    $reason The reason why the value could not be
47
     *                          unserialized.
48
     * @param int       $code   The exception code.
49
     * @param Exception $cause  The exception that caused this exception.
50
     *
51
     * @return static The new exception.
52
     */
53
    public static function forType($type, $reason = '', $code = 0, Exception $cause = null)
54
    {
55
        return new static(sprintf(
56
            'Could not serialize value of type %s%s',
57
            $type,
58
            $reason ? ': '.$reason : '.'
59
        ), $code, $cause);
60
    }
61
}
62

src/Api/UnserializationFailedException.php 1 location

@@ 24-61 (lines=38) @@
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 */
24
class UnserializationFailedException extends RuntimeException
25
{
26
    /**
27
     * Creates a new exception for the given value.
28
     *
29
     * @param mixed     $value  The value that could not be unserialized.
30
     * @param string    $reason The reason why the value could not be
31
     *                          unserialized.
32
     * @param int       $code   The exception code.
33
     * @param Exception $cause  The exception that caused this exception.
34
     *
35
     * @return static The new exception.
36
     */
37
    public static function forValue($value, $reason = '', $code = 0, Exception $cause = null)
38
    {
39
        return self::forType(is_object($value) ? get_class($value) : gettype($value), $reason, $code, $cause);
40
    }
41
42
    /**
43
     * Creates a new exception for the given value type.
44
     *
45
     * @param string    $type   The type that could not be unserialized.
46
     * @param string    $reason The reason why the value could not be
47
     *                          unserialized.
48
     * @param int       $code   The exception code.
49
     * @param Exception $cause  The exception that caused this exception.
50
     *
51
     * @return static The new exception.
52
     */
53
    public static function forType($type, $reason = '', $code = 0, Exception $cause = null)
54
    {
55
        return new static(sprintf(
56
            'Could not unserialize value of type %s%s',
57
            $type,
58
            $reason ? ': '.$reason : '.'
59
        ), $code, $cause);
60
    }
61
}
62