ObjectWriteException   A
last analyzed

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
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