Passed
Push — master ( 9a9b0b...b778d8 )
by Peter
08:40
created

addBlankLineIndentsByHisParent()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
ccs 15
cts 15
cp 1
rs 9.4888
cc 5
nc 4
nop 2
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Model\Component\Parser;
6
7
use YamlStandards\Model\Component\YamlService;
8
9
class YamlParserService
10
{
11
    /**
12
     * @param string[] $fileLines
13
     * @param int $key
14
     * @return string
15
     */
16 6
    public static function addBlankLineIndentsByHisParent(array $fileLines, int $key): string
17
    {
18 6
        $currentLine = $fileLines[$key];
19 6
        $arrayKeys = array_keys($fileLines);
20 6
        $lastKey = end($arrayKeys);
21 6
        $indents = '';
22
23 6
        if (YamlService::isLineNotBlank($currentLine)) {
24 6
            return $currentLine;
25
        }
26
27 6
        while ($key < $lastKey) {
28 6
            $key++;
29 6
            $line = $fileLines[$key];
30
31 6
            if (YamlService::isLineNotBlank($line) && YamlService::isLineComment($line) === false) {
32 5
                $countOfRowIndents = YamlService::rowIndentsOf($line);
33 5
                $indents = YamlService::createCorrectIndentsByCountOfIndents($countOfRowIndents);
34 5
                break;
35
            }
36
        }
37
38 6
        return $indents . $currentLine;
39
    }
40
}
41