Failed Conditions
Pull Request — develop (#3131)
by Michael
60:38
created

SerializationFailed::new()   A

Complexity

Conditions 2
Paths 2

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 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', as an '%s' error was triggered by the serialization",
25
                $actualType,
26
                $format,
27
                $error
28
            )
29
        );
30
    }
31
}
32