CouldNotConvertException::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace W2w\Lib\ApieObjectAccessNormalizer\Exceptions;
4
5
use W2w\Lib\ApieObjectAccessNormalizer\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