-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTypeError.php
More file actions
29 lines (26 loc) · 743 Bytes
/
Copy pathTypeError.php
File metadata and controls
29 lines (26 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
declare(strict_types=1);
namespace JsonMapper\Exception;
class TypeError extends \TypeError
{
/** @param mixed $argument */
public static function forArgument(
string $method,
string $expectedType,
$argument,
int $argumentNumber,
string $argumentName
): TypeError {
$trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
return new TypeError(\sprintf(
'%s(): Argument #%d (%s) must be of type %s, %s given, called in %s on line %d',
$method,
$argumentNumber,
$argumentName,
$expectedType,
gettype($argument),
$trace[1]['file'],
$trace[1]['line']
));
}
}