getCorrectYamlContent()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 19
ccs 13
cts 13
cp 1
crap 4
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Model\YamlEmptyLineAtEnd;
6
7
use YamlStandards\Model\Component\YamlService;
8
9
class YamlEmptyLineAtEndDataFactory
10
{
11
    /**
12
     * @param string[] $yamlLines
13
     * @return string[]
14
     */
15 10
    public static function getCorrectYamlContent(array $yamlLines): array
16
    {
17 10
        $reversedYamlLines = array_reverse($yamlLines, true);
18 10
        $keys = array_keys($reversedYamlLines);
19 10
        $lastKey = end($keys);
20
21 10
        foreach ($reversedYamlLines as $key => $yamlLine) {
22 10
            if (YamlService::isLineNotBlank($yamlLine)) {
23 9
                $yamlLines = array_slice($yamlLines, 0, $key + 1);
24 9
                $yamlLines[] = '';
25 9
                break;
26
            }
27 9
            if ($key === $lastKey) {
28 1
                $yamlLines = [''];
29 1
                break;
30
            }
31
        }
32
33 10
        return $yamlLines;
34
    }
35
}
36