public static function invalidValueForType($type, $expected, $got)
{
if (is_array($expected)) {
$expected = sprintf('%s or %s', join(', ', array_slice($expected, 0, -1)), end($expected));
}
if (is_object($got)) {
$gotType = get_class($got);
} elseif (is_array($got)) {
$gotType = 'array';
} else {
$gotType = 'scalar';
}
return new self(sprintf('%s type requires value of type %s, %s given', $type, $expected, $gotType));
}