Passed
Push — master ( 65d8ad...c74ce3 )
by Pieter
04:45 queued 14s
created

InvalidValueForValueObjectException::getI18n()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
namespace W2w\Lib\Apie\Exceptions;
3
4
use ReflectionClass;
5
use W2w\Lib\ApieObjectAccessNormalizer\Exceptions\LocalizationableException;
6
use W2w\Lib\ApieObjectAccessNormalizer\Exceptions\LocalizationInfo;
7
8
class InvalidValueForValueObjectException extends ApieException implements LocalizationableException
0 ignored issues
show
Deprecated Code introduced by
The class W2w\Lib\Apie\Exceptions\ApieException has been deprecated: use \W2w\Lib\ApieObjectAccessNormalizer\Exceptions\ApieException ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

8
class InvalidValueForValueObjectException extends /** @scrutinizer ignore-deprecated */ ApieException implements LocalizationableException
Loading history...
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
15
    /**
16
     * @var mixed
17
     */
18
    private $value;
19
20
    public function __construct($value, $valueObject)
21
    {
22
        $refl = new ReflectionClass($valueObject);
23
        $this->name = strtolower((string) preg_replace('/(?<!^)[A-Z]/', '_$0', $refl->getShortName()));
24
        $this->value = $value;
25
        parent::__construct(
26
            422,
27
            '"' . $value . '" is not a valid value for value object ' . $this->name
28
        );
29
    }
30
31
    public function getI18n(): LocalizationInfo
32
    {
33
        return new LocalizationInfo(
34
            'validation.format',
35
            [
36
                'name' => $this->name,
37
                'value' => $this->value,
38
            ]
39
        );
40
    }
41
}
42