| Total Complexity | 5 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 10 | final class UnexpectedResultType extends RuntimeException implements AssertionError |
||
| 11 | { |
||
| 12 | private mixed $result; |
||
| 13 | |||
| 14 | private string $expected; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param mixed $result |
||
| 18 | * @param string $expected |
||
| 19 | * @return static |
||
| 20 | */ |
||
| 21 | public static function fromResult(mixed $result, string $expected): self |
||
| 22 | { |
||
| 23 | $msg = sprintf( |
||
| 24 | 'Expected result of type %s, instead received an instance of %s', |
||
| 25 | $expected, |
||
| 26 | (is_object($result)) ? get_class($result) : gettype($result) |
||
| 27 | ); |
||
| 28 | |||
| 29 | return new self($msg, $expected, $result); |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param string $message |
||
| 34 | * @param string $expected |
||
| 35 | * @param mixed $result |
||
| 36 | */ |
||
| 37 | private function __construct(string $message, string $expected, mixed $result) |
||
| 38 | { |
||
| 39 | $this->expected = $expected; |
||
| 40 | $this->result = $result; |
||
| 41 | |||
| 42 | parent::__construct($message); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @return mixed |
||
| 47 | */ |
||
| 48 | public function getResult(): mixed |
||
| 49 | { |
||
| 50 | return $this->result; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getExpected(): string |
||
| 59 | } |
||
| 60 | } |
||
| 61 |