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

ObjectAccessException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getI18n() 0 7 1
A __construct() 0 8 1
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