Passed
Push — master ( 94b934...c658e2 )
by Marius
04:22 queued 42s
created

ExtendedWriter::add()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 13
cts 13
cp 1
rs 9.2568
c 0
b 0
f 0
cc 5
nc 4
nop 1
crap 5
1
<?php
2
declare(strict_types=1);
3
4
namespace Paysera\PhpStormHelper\Service\Gitignore;
5
6
use GitIgnoreWriter\GitIgnoreWriter;
7
8
class ExtendedWriter extends GitIgnoreWriter
9
{
10
11 9
    public function add($input)
12
    {
13 9
        $inputLines = $this->parseInput($input);
14
15 9
        $commentSection = [];
16 9
        $lines = [];
17 9
        foreach($inputLines as $k => $line) {
18 8
            if ($line === '' || $line[0] === '#') {
19 7
                $commentSection[] = $line;
20 7
                continue;
21
            }
22
23 8
            if (!$this->exists($line)) {
24 7
                $lines = array_merge($lines, $commentSection);
25 7
                $lines[] = $line;
26
            }
27
28 8
            $commentSection = [];
29
        }
30
31 9
        return parent::add($lines);
32
    }
33
}
34