CouldNotConvertException   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 9
c 1
b 0
f 1
dl 0
loc 24
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getI18n() 0 5 1
1
<?php
2
3
namespace Apie\ObjectAccessNormalizer\Exceptions;
4
5
use Apie\ObjectAccessNormalizer\Utils;
6
7
/**
8
 * Thrown if a value can not be converted to a built in php type.
9
 *
10
 * @see Utils
11
 */
12
class CouldNotConvertException extends ApieException implements LocalizationableException
13
{
14
    /**
15
     * @var string
16
     */
17
    private $wantedType;
18
19
    /**
20
     * @var string
21
     */
22
    private $displayValue;
23
24
    public function __construct(string $wantedType, string $displayValue)
25
    {
26
        $this->wantedType = $wantedType;
27
        $this->displayValue = $displayValue;
28
        parent::__construct(429, 'must be one of "' . $wantedType . '" ("' . $displayValue . '" given)');
29
    }
30
31
    public function getI18n(): LocalizationInfo
32
    {
33
        return new LocalizationInfo(
34
            'serialize.conversion_error',
35
            ['wanted' => $this->wantedType, 'given' => $this->displayValue]
36
        );
37
    }
38
}
39