Failed Conditions
Pull Request — develop (#3525)
by Jonathan
09:58
created

ValueNotConvertible   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 19
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A new() 0 17 4
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 is_string;
9
use function sprintf;
10
use function strlen;
11
use function substr;
12
13
/**
14
 * Thrown when a Database to Doctrine Type Conversion fails.
15
 */
16
final class ValueNotConvertible extends ConversionException implements TypesException
17
{
18 328
    public static function new($value, $toType, ?string $message = null) : self
19
    {
20 328
        if ($message !== null) {
21 304
            return new self(
22 304
                sprintf(
23 4
                    "Could not convert database value to '%s' as an error was triggered by the unserialization: '%s'",
24 304
                    $toType,
25 304
                    $message
26
                )
27
            );
28
        }
29
30 299
        return new self(
31 299
            sprintf(
32 24
                'Could not convert database value "%s" to Doctrine Type %s',
33 299
                is_string($value) && strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value,
34 299
                $toType
35
            )
36
        );
37
    }
38
}
39