StringConverter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 24
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convertToString() 0 16 6
1
<?php
2
3
namespace Metabor;
4
5
use MetaborStd\NamedInterface;
6
use MetaborStd\StringConverterInterface;
7
8
/**
9
 * @author Oliver Tischlinger
10
 */
11
class StringConverter implements StringConverterInterface
12
{
13
    /**
14
     * @param mixed $source
15
     *
16
     * @return string
17
     */
18 1
    public function convertToString($source)
19
    {
20 1
        if (is_object($source)) {
21 1
            if ($source instanceof NamedInterface) {
22 1
                return $source->getName();
23
            } elseif (method_exists($source, '__toString')) {
24
                return (string) $source;
25
            } else {
26
                return get_class($source);
27
            }
28
        } elseif (is_scalar($source) || is_null($source)) {
29
            return (string) $source;
30
        } else {
31
            return gettype($source);
32
        }
33
    }
34
}
35