Failed Conditions
Push — master ( 01c22b...e42c1f )
by Marco
79:13 queued 10s
created

SerializationFailed::new()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 10
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\DBAL\Types\Exception;
6
7
use Doctrine\DBAL\Types\ConversionException;
8
use function get_class;
9
use function gettype;
10
use function is_object;
11
use function sprintf;
12
13
final class SerializationFailed extends ConversionException implements TypesException
14
{
15
    /**
16
     * @param mixed $value
17
     */
18
    public static function new($value, string $format, string $error) : self
19
    {
20
        $actualType = is_object($value) ? get_class($value) : gettype($value);
21
22
        return new self(
23
            sprintf(
24
                'Could not convert PHP type "%s" to "%s". An error was triggered by the serialization: %s',
25
                $actualType,
26
                $format,
27
                $error
28
            )
29
        );
30
    }
31
}
32