ObjectAccessException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getI18n() 0 7 1
A __construct() 0 8 1
1
<?php
2
3
namespace Apie\ObjectAccessNormalizer\Exceptions;
4
5
use Apie\ObjectAccessNormalizer\Getters\GetterInterface;
6
use Throwable;
7
8
/**
9
 * Exception thrown when trying to get a property value.
10
 */
11
class ObjectAccessException extends ApieException implements LocalizationableException
12
{
13
    /**
14
     * @var string
15
     */
16
    private $name;
17
18
    /**
19
     * @param GetterInterface $method
20
     * @param string $fieldName
21
     * @param Throwable $previous
22
     */
23
    public function __construct(
24
        GetterInterface $method,
25
        string $fieldName,
26
        Throwable $previous
27
    ) {
28
        $this->name = $method->getName();
29
        $message = 'Could not access property "' . $fieldName . '" from ' . $this->name . ': ' . $previous->getMessage();
30
        parent::__construct(500, $message, $previous);
31
    }
32
33
    public function getI18n(): LocalizationInfo
34
    {
35
        return new LocalizationInfo(
36
            'serialize.read',
37
            [
38
                'name' => $this->name,
39
                'previous' => $this->getPrevious()->getMessage(),
40
            ]
41
        );
42
    }
43
}
44