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

YamlAlphabeticalChecker::sortArrayKeyWithUnderscoresAsFirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YamlStandards\Model\YamlAlphabetical;
6
7
use SebastianBergmann\Diff\Differ;
8
use Symfony\Component\Yaml\Yaml;
9
use YamlStandards\Command\ProcessOutput;
10
use YamlStandards\Model\AbstractChecker;
11
use YamlStandards\Model\Config\StandardParametersData;
12
use YamlStandards\Result\Result;
13
14
/**
15
 * Check yaml file is alphabetical sorted
16
 */
17
class YamlAlphabeticalChecker extends AbstractChecker
18
{
19
    /**
20
     * @inheritDoc
21
     */
22 4
    public function check(string $pathToYamlFile, StandardParametersData $standardParametersData): Result
23
    {
24 4
        $fileContent = file_get_contents($pathToYamlFile);
25 4
        $fileContent = str_replace("\r", '', $fileContent); // remove carriage returns
26
27 4
        $rightFileLines = YamlAlphabeticalDataFactory::getCorrectYamlLines($pathToYamlFile, $standardParametersData->getDepth());
28
29 4
        $rightFileContent = implode("\n", $rightFileLines);
30
31 4
        if ($fileContent === $rightFileContent) {
32 4
            return new Result($pathToYamlFile, Result::RESULT_CODE_OK, ProcessOutput::STATUS_CODE_OK);
33
        }
34
35
        $differ = new Differ();
36
        $diffBetweenStrings = $differ->diff($fileContent, $rightFileContent);
37
38
        return new Result($pathToYamlFile, Result::RESULT_CODE_INVALID_FILE_SYNTAX, ProcessOutput::STATUS_CODE_INVALID_FILE_SYNTAX, $diffBetweenStrings);
39
    }
40
}
41