ObjectWriteException::__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 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
use W2w\Lib\ApieObjectAccessNormalizer\Setters\SetterInterface;
9
10
/**
11
 * Exception thrown when a value could not be set.
12
 */
13
class ObjectWriteException extends ApieException implements LocalizationableException
14
{
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
20
    /**
21
     * @param SetterInterface $method
22
     * @param string $fieldName
23
     * @param Throwable $previous
24
     */
25
    public function __construct(
26
        SetterInterface $method,
27
        string $fieldName,
28
        Throwable $previous
29
    ) {
30
        $this->name = $method->getName();
31
        $message = 'Could not write property "' . $fieldName . '" with ' . $this->name . ': ' . $previous->getMessage();
32
        parent::__construct(500, $message, $previous);
33
    }
34
35
    public function getI18n(): LocalizationInfo
36
    {
37
        return new LocalizationInfo(
38
            'serialize.write',
39
            [
40
                'name' => $this->name,
41
                'previous' => $this->getPrevious()->getMessage(),
42
            ]
43
        );
44
    }
45
}
46