Completed
Push — master ( 984c1e...c9a923 )
by Karsten
03:26
created

ToString::__invoke()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 6
nc 3
nop 1
crap 4
1
<?php
2
/**
3
 * Created by gerk on 20.11.17 17:34
4
 */
5
6
namespace PeekAndPoke\Component\Psi\Psi\Str;
7
8
use PeekAndPoke\Component\Psi\Interfaces\UnaryFunction;
9
10
/**
11
 *
12
 *
13
 * @author Karsten J. Gerber <[email protected]>
14
 */
15
class ToString implements UnaryFunction
16
{
17
18
    /**
19
     * @param mixed $input
20
     *
21
     * @return mixed
22
     */
23 31
    public function __invoke($input)
24
    {
25 31
        if (is_scalar($input)) {
26 19
            return (string) $input;
27
        }
28
29 12
        if (is_object($input) && method_exists($input, '__toString')) {
30 3
            return (string) $input;
31
        }
32
33 9
        return '';
34
    }
35
}
36