blob: 4fb0450a061837a4d2be609100c268c92cdaf532 (
plain) (
blame)
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
30
31
32
33
34
35
|
<?php
declare(strict_types=1);
namespace League\HTMLToMarkdown;
/**
* @internal
*/
final class Coerce
{
private function __construct()
{
}
/**
* @param mixed $val
*/
public static function toString($val): string
{
switch (true) {
case \is_string($val):
return $val;
case \is_bool($val):
case \is_float($val):
case \is_int($val):
case $val === null:
return \strval($val);
case \is_object($val) && \method_exists($val, '__toString'):
return $val->__toString();
default:
throw new \InvalidArgumentException('Cannot coerce this value to string');
}
}
}
|