| Total Complexity | 6 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class InvalidTypeDtoException extends TypeError |
||
| 9 | { |
||
| 10 | public function __construct(PropertyContract $property, $value) |
||
| 11 | { |
||
| 12 | $value = $this->resolveTypeFromValue($value); |
||
| 13 | |||
| 14 | $expectedTypes = $this->resolveExpectedTypes($property); |
||
| 15 | |||
| 16 | parent::__construct("Invalid type: expected {$property->getFqn()} to be of type {$expectedTypes}, instead got value `{$value}`."); |
||
| 17 | } |
||
| 18 | |||
| 19 | protected function resolveTypeFromValue($value): string |
||
| 20 | { |
||
| 21 | if ($value === null) { |
||
| 22 | $value = 'null'; |
||
| 23 | } |
||
| 24 | |||
| 25 | if (is_object($value)) { |
||
| 26 | $value = get_class($value); |
||
| 27 | } |
||
| 28 | |||
| 29 | if (is_array($value)) { |
||
| 30 | $value = 'array'; |
||
| 31 | } |
||
| 32 | |||
| 33 | return $value; |
||
| 34 | } |
||
| 35 | |||
| 36 | protected function resolveExpectedTypes(PropertyContract $property) |
||
| 39 | } |
||
| 40 | } |
||
| 41 |