Parser   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 37
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareLines() 0 3 1
A __construct() 0 3 1
A cleanLine() 0 4 2
A explodeLines() 0 15 3
1
<?php
2
3
// https://github.com/m1/Env/blob/master/src/Parser/ValueParser.php
4
5
namespace Codervio\Envmanager\Parser;
6
7
use Codervio\Envmanager\Resolver\ArrayStore;
8
9
class Parser
10
{
11
    public $arr;
12
    private $data;
13
14
    public function __construct()
15
    {
16
        $this->arr = new ArrayStore();
17
    }
18
19
    public function prepareLines($input)
20
    {
21
        return str_replace(array('\n', '\r\n', '\r'), PHP_EOL, $input);
22
    }
23
24
    public function explodeLines($data)
25
    {
26
        $this->data = explode("\n", str_replace(array("\r\n", "\n\r", "\r"), "\n", $data));
27
28
        if (is_array($this->data)) {
0 ignored issues
show
introduced by
The condition is_array($this->data) is always true.
Loading history...
29
30
            foreach ($this->data as $key => $val) {
31
32
                $this->arr->append($val);
33
34
                $this->cleanLine($key, $val);
35
36
            }
37
        } else {
38
            return;
39
        }
40
    }
41
42
    private function cleanLine($key, $line)
43
    {
44
        if (empty($line)) {
45
            $this->arr->offsetUnset($key);
46
        }
47
    }
48
}