Passed
Push — master ( e0b9fb...8b102c )
by Pieter
03:24
created

ObjectAccessException::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace W2w\Lib\ApieObjectAccessNormalizer\Exceptions;
4
5
use ReflectionMethod;
6
use ReflectionProperty;
7
use Throwable;
8
9
/**
10
 * Exception thrown when trying to get a property value.
11
 */
12
class ObjectAccessException extends ApieException implements LocalizationableException
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     * @param ReflectionMethod|ReflectionProperty $method
21
     * @param string $fieldName
22
     * @param Throwable $previous
23
     */
24
    public function __construct(
25
        $method,
26
        string $fieldName,
27
        Throwable $previous
28
    ) {
29
        $this->name = $method->getName();
30
        $message = 'Could not access property "' . $fieldName . '" from ' . $this->name . ': ' . $previous->getMessage();
31
        parent::__construct(500, $message, $previous);
32
    }
33
34
    public function getI18n(): LocalizationInfo
35
    {
36
        return new LocalizationInfo(
37
            'serialize.read',
38
            [
39
                'name' => $this->name,
40
                'previous' => $this->getPrevious()->getMessage(),
41
            ]
42
        );
43
    }
44
}
45