1 | <?php |
||
2 | /** |
||
3 | * Webino™ (http://webino.sk) |
||
4 | * |
||
5 | * @link https://github.com/webino/exceptions |
||
6 | * @copyright Copyright (c) 2019 Webino, s.r.o. (http://webino.sk) |
||
7 | * @author Peter Bačinský <[email protected]> |
||
8 | * @license BSD-3-Clause |
||
9 | */ |
||
10 | |||
11 | namespace Webino; |
||
12 | |||
13 | /** |
||
14 | * Trait ExceptionFormatTrait |
||
15 | * |
||
16 | * Used to format the exception message. |
||
17 | * |
||
18 | * @package exception |
||
19 | */ |
||
20 | trait ExceptionFormatTrait |
||
21 | { |
||
22 | /** |
||
23 | * Format the exception message via sprintf() |
||
24 | * |
||
25 | * @param array<int, mixed> $params Message parameters |
||
26 | * @return $this |
||
27 | */ |
||
28 | public function format(...$params) |
||
29 | { |
||
30 | if (empty($this->message)) { |
||
31 | return $this; |
||
32 | } |
||
33 | |||
34 | $args = [$this->message]; |
||
35 | foreach ($params as $param) { |
||
36 | if (is_string($param)) { |
||
37 | $args[] = '`' . $param . '`'; |
||
38 | } elseif (is_object($param)) { |
||
39 | $args[] = '`' . get_class($param) . '`'; |
||
40 | } else { |
||
41 | $args[] = '`' . var_export($param, true) . '`'; |
||
42 | } |
||
43 | } |
||
44 | |||
45 | $this->message = call_user_func('sprintf', ...$args); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
46 | return $this; |
||
47 | } |
||
48 | } |
||
49 |