fromSerializationTriggeredException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Doctrine\Instantiator\Exception;
4
5
use Exception;
6
use ReflectionClass;
7
use UnexpectedValueException as BaseUnexpectedValueException;
8
use function sprintf;
9
10
/**
11
 * Exception for given parameters causing invalid/unexpected state on instantiation
12
 */
13
class UnexpectedValueException extends BaseUnexpectedValueException implements ExceptionInterface
14
{
15 1
    public static function fromSerializationTriggeredException(
16
        ReflectionClass $reflectionClass,
17
        Exception $exception
18
    ) : self {
19 1
        return new self(
20 1
            sprintf(
21 1
                'An exception was raised while trying to instantiate an instance of "%s" via un-serialization',
22 1
                $reflectionClass->getName()
0 ignored issues
show
Bug introduced by
Consider using $reflectionClass->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
23
            ),
24 1
            0,
25 1
            $exception
26
        );
27
    }
28
29 1
    public static function fromUncleanUnSerialization(
30
        ReflectionClass $reflectionClass,
31
        string $errorString,
32
        int $errorCode,
33
        string $errorFile,
34
        int $errorLine
35
    ) : self {
36 1
        return new self(
37 1
            sprintf(
38
                'Could not produce an instance of "%s" via un-serialization, since an error was triggered '
39 1
                . 'in file "%s" at line "%d"',
40 1
                $reflectionClass->getName(),
0 ignored issues
show
Bug introduced by
Consider using $reflectionClass->name. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
41 1
                $errorFile,
42 1
                $errorLine
43
            ),
44 1
            0,
45 1
            new Exception($errorString, $errorCode)
46
        );
47
    }
48
}
49