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

InvalidValueForValueObjectException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 30
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
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