ExtendedWriter::add()   A
last analyzed

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 5
    public function add($input)
11
    {
12 5
        $inputLines = $this->parseInput($input);
13
14 5
        $commentSection = [];
15 5
        $lines = [];
16 5
        foreach ($inputLines as $k => $line) {
17 4
            if ($line === '' || $line[0] === '#') {
18 3
                $commentSection[] = $line;
19 3
                continue;
20
            }
21
22 4
            if (!$this->exists($line)) {
23 3
                $lines = array_merge($lines, $commentSection);
24 3
                $lines[] = $line;
25
            }
26
27 4
            $commentSection = [];
28
        }
29
30 5
        return parent::add($lines);
31
    }
32
}
33