1: <?php
2:
3: namespace Chromabits\Nucleus\Data\Exceptions;
4:
5: use Chromabits\Nucleus\Exceptions\CoreException;
6: use Chromabits\Nucleus\Meditation\TypeHound;
7:
8: 9: 10: 11: 12: 13:
14: class MismatchedDataTypesException extends CoreException
15: {
16: 17: 18:
19: protected $expected;
20:
21: 22: 23:
24: protected $received;
25:
26: 27: 28: 29: 30: 31:
32: public function __construct($expected, $received)
33: {
34: parent::__construct('', null, null);
35:
36: $this->setExpectedAndReceived($expected, $received);
37: }
38:
39: 40: 41: 42: 43: 44: 45: 46:
47: public static function create($expected, $received)
48: {
49: return new MismatchedDataTypesException($expected, $received);
50: }
51:
52: 53: 54: 55: 56: 57:
58: public function setExpectedAndReceived($expected, $received)
59: {
60: $this->expected = is_string($expected)
61: ? $expected : get_class($expected);
62:
63: $this->received = TypeHound::fetch($received);
64:
65: $this->message = vsprintf(
66: 'An instance of a %s was expected but got %s',
67: [$this->expected, $this->received]
68: );
69: }
70:
71: 72: 73:
74: public function getExpected()
75: {
76: return $this->expected;
77: }
78:
79: 80: 81:
82: public function getReceived()
83: {
84: return $this->received;
85: }
86: }
87: