runCheckYamlFileIsValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Model\YamlEmptyLineAtEnd;
6
7
use SebastianBergmann\Diff\Differ;
8
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
9
use YamlStandards\Model\AbstractChecker;
10
use YamlStandards\Model\Config\StandardParametersData;
11
use YamlStandards\Result\Result;
12
13
/**
14
 * Check yaml file has empty line at end of file
15
 */
16
class YamlEmptyLineAtEndChecker extends AbstractChecker
17
{
18
    /**
19
     * @inheritDoc
20
     */
21 4
    public function check(string $pathToFile, StandardParametersData $standardParametersData): Result
22
    {
23 4
        $yamlContent = file_get_contents($pathToFile);
24 4
        $yamlContent = str_replace("\r", '', $yamlContent); // remove carriage returns
25 4
        $yamlLines = explode("\n", $yamlContent);
26
27 4
        $correctYamlLines = YamlEmptyLineAtEndDataFactory::getCorrectYamlContent($yamlLines);
28 4
        $correctYamlContent = implode("\n", $correctYamlLines);
29
30 4
        if ($yamlContent === $correctYamlContent) {
31 3
            return new Result($pathToFile, Result::RESULT_CODE_OK);
32
        }
33
34 1
        $differ = new Differ(new UnifiedDiffOutputBuilder());
35 1
        $diffBetweenStrings = $differ->diff($yamlContent, $correctYamlContent);
36
37 1
        return new Result($pathToFile, Result::RESULT_CODE_INVALID_FILE_SYNTAX, $diffBetweenStrings, true);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 2
    protected function runCheckYamlFileIsValid(string $pathToYamlFile): void
44
    {
45 2
    }
46
}
47