ObjectAccessException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 8
rs 10
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