PHPConstantsOutputAdapter   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 88.46%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 44
ccs 23
cts 26
cp 0.8846
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addSlashes() 0 4 1
A process() 0 8 2
A getName() 0 4 1
B serialize() 0 17 8
1
<?php
2
3
namespace Paro\EnvironmentParameters\Adapter\Output;
4
5
6
class PHPConstantsOutputAdapter implements OutputAdapterInterface
7
{
8 1
    public static function getName()
9
    {
10 1
        return 'php-constants';
11
    }
12
13 2
    public function process($parameters, $fileName, $env, $date)
14
    {
15 2
        $content = sprintf("<?php\n/** This file is auto-generated during the build process of '%s' environment at %s **/\n", $env, date(DATE_ATOM, $date));
16 2
        foreach ($parameters as $key => $value) {
17 2
            $content .= sprintf("define('%s', %s);\n", $key, $this->serialize($value));
18 2
        };
19 2
        file_put_contents($fileName, $content);
20 2
    }
21
22
    /**
23
     * @param $value
24
     * @return string
25
     */
26 2
    protected function serialize($value)
27
    {
28 2
        switch (gettype($value)) {
29 2
            case 'boolean':
30 1
                return $value ? 'true' : 'false';
31 2
            case 'array':
32 2
            case 'object':
33 1
                return "'" . $this->addSlashes(serialize($value)) . "'";
34 2
            case 'NULL':
35 1
                return "null";
36 1
            case 'integer':
37 1
            case 'double':
38 1
                return $value;
39
            default:
40
                return "'" . $this->addSlashes($value) . "'";
41
        }
42
    }
43
44 1
    private function addSlashes($value)
45
    {
46 1
        return str_replace("'", "\\'", $value);
47
    }
48
49
}