Lines 100.00% 4 / 4
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
JsonShapeException 100.00% 4 / 4 100.00% 3 / 3 5 100.00% 1 / 1
 wrongType 100.00% 1 / 1 100.00% 1 / 1 1
 missing 100.00% 1 / 1 100.00% 1 / 1 1
 unexpectedValue 100.00% 2 / 2 100.00% 1 / 1 3
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Support\Exception;
6
7use Stewart\Contracts\Exception\StewartException;
8
9/**
10 * @internal
11 * @extends StewartException<JsonShapeError>
12 */
13final class JsonShapeException extends StewartException
14{
15    public static function wrongType(string $key, string $expected, string $actualType): self
16    {
17        return self::createForReason(JsonShapeError::WrongType, key: $key, expected: $expected, actualType: $actualType);
18    }
19
20    public static function missing(string $key, string $expected): self
21    {
22        return self::createForReason(JsonShapeError::Missing, key: $key, expected: $expected);
23    }
24
25    public static function unexpectedValue(string $key, string $expected, mixed $value): self
26    {
27        $shown = \is_string($value) ? '"' . $value . '"' : (\is_scalar($value) ? var_export($value, true) : get_debug_type($value));
28
29        return self::createForReason(JsonShapeError::UnexpectedValue, key: $key, expected: $expected, value: $shown);
30    }
31}