InvalidInputException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getFieldName() 0 3 1
1
<?php
2
3
4
namespace Apie\TypeJuggling\Exceptions;
5
6
use Apie\Core\Exceptions\ApieException;
7
use Apie\Core\Exceptions\FieldNameAwareInterface;
8
use Apie\TypeJuggling\TypeUtilInterface;
9
10
/**
11
 * Thrown when a type could not be converted into the native type.
12
 */
13
class InvalidInputException extends ApieException implements FieldNameAwareInterface
14
{
15
    private $fieldName;
16
17
    public function __construct(string $fieldName, TypeUtilInterface $typeUtil, $input)
18
    {
19
        $this->fieldName = $fieldName;
20
        $type =  get_debug_type($input);
21
        if (is_array($input)) {
22
            $type = json_encode($input);
23
        }
24
        $message = 'Wrong input for field "' . $fieldName . '" expect '. $typeUtil . ' got ' . $type;
25
        parent::__construct(422, $message);
26
    }
27
28
    /**
29
     * @return string
30
     */
31
    public function getFieldName(): string
32
    {
33
        return $this->fieldName;
34
    }
35
}
36