Passed
Pull Request — master (#239)
by Colin
21:48
created

Coerce::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 1
b 0
f 0
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):
0 ignored issues
show
Bug introduced by
The function is_string was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
            case /** @scrutinizer ignore-call */ \is_string($val):
Loading history...
23
                return $val;
24
            case \is_bool($val):
0 ignored issues
show
Bug introduced by
The function is_bool was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
            case /** @scrutinizer ignore-call */ \is_bool($val):
Loading history...
25
            case \is_float($val):
0 ignored issues
show
Bug introduced by
The function is_float was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
            case /** @scrutinizer ignore-call */ \is_float($val):
Loading history...
26
            case \is_int($val):
0 ignored issues
show
Bug introduced by
The function is_int was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
            case /** @scrutinizer ignore-call */ \is_int($val):
Loading history...
27
            case \is_null($val):
0 ignored issues
show
Bug introduced by
The function is_null was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
            case /** @scrutinizer ignore-call */ \is_null($val):
Loading history...
28
                return \strval($val);
0 ignored issues
show
Bug introduced by
The function strval was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
                return /** @scrutinizer ignore-call */ \strval($val);
Loading history...
29
            case \is_object($val) && \method_exists($val, '__toString'):
0 ignored issues
show
Bug introduced by
The function is_object was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
            case /** @scrutinizer ignore-call */ \is_object($val) && \method_exists($val, '__toString'):
Loading history...
30
                return $val->__toString();
31
            default:
32
                throw new \InvalidArgumentException('Cannot coerce this value to string');
33
        }
34
    }
35
}