Coerce   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toString() 0 14 8
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\HTMLToMarkdown;
6
7
/**
8
 * @internal
9
 */
10
final class Coerce
11
{
12
    private function __construct()
13
    {
14
    }
15
16
    /**
17
     * @param mixed $val
18
     */
19
    public static function toString($val): string
20
    {
21
        switch (true) {
22
            case \is_string($val):
23
                return $val;
24
            case \is_bool($val):
25
            case \is_float($val):
26
            case \is_int($val):
27
            case $val === null:
28
                return \strval($val);
29
            case \is_object($val) && \method_exists($val, '__toString'):
30
                return $val->__toString();
31
            default:
32
                throw new \InvalidArgumentException('Cannot coerce this value to string');
33
        }
34
    }
35
}
36