Formatter   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addEmptyLine() 0 3 1
A formatComment() 0 3 1
A formatSetter() 0 13 3
A setKeys() 0 14 5
1
<?php
2
3
namespace Codervio\Envmanager\Editor;
4
5
class Formatter
6
{
7
    protected $values = null;
8
9
    public function setKeys($item)
10
    {
11
        if (array_key_exists('key', $item)) {
12
            $key = $item['key'];
13
            $value = array_key_exists('value', $item) ? '"'.$item['value'].'"' : null;
14
            $comment = array_key_exists('comment', $item) ? $item['comment'] : null;
15
            $export = array_key_exists('export', $item) ? $item['export'] : null;
16
17
            $packArray = compact('key', 'value', 'comment', 'export');
18
19
            $this->values = $packArray;
20
        }
21
22
        return $this->values;
23
    }
24
25
    public function formatSetter($value)
26
    {
27
        if ($value['export']) {
28
            $value['export'] = 'export ';
29
        } else {
30
            $value['export'] = '';
31
        }
32
33
        if (isset($value['comment'])) {
34
            $value['comment'] = ' # '.$value['comment'];
35
        }
36
37
        return (string)"{$value['export']}{$value['key']}={$value['value']}{$value['comment']}";
38
    }
39
40
    public function formatComment($comment)
41
    {
42
        return (string)'# '.$comment;
43
    }
44
45
    public function addEmptyLine()
46
    {
47
        return (string)PHP_EOL;
48
    }
49
}