StringFactoryFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 5 1
A factoryClassName() 0 10 3
A format() 0 4 1
1
<?php
2
3
namespace Glooby\Debug\Formatter;
4
use Glooby\Debug\Exception\FormatterException;
5
6
/**
7
 * @author Emil Kilhage
8
 */
9
class StringFactoryFormatter implements FormatterInterface
10
{
11
    /**
12
     * @param string $string
13
     * @return FormatterInterface
14
     */
15
    public static function factory($string)
16
    {
17
        $className = self::factoryClassName($string);
18
        return new $className();
19
    }
20
21
    /**
22
     * @param string $string
23
     * @return FormatterInterface
24
     */
25
    public static function factoryClassName($string)
26
    {
27
        if (JsonStringFormatter::isJsonString($string)) {
28
            return JsonStringFormatter::class;
29
        } elseif (XmlStringFormatter::isXmlString($string)) {
30
            return XmlStringFormatter::class;
31
        } else {
32
            return StringFormatter::class;
33
        }
34
    }
35
36
    /**
37
     * @param mixed $response
38
     * @return string
39
     * @throws FormatterException
40
     */
41
    public function format($response)
42
    {
43
        return self::factory($response)->format($response);
44
    }
45
}
46