Conditions | 2 |
Paths | 2 |
Total Lines | 19 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 3 | public function fix(string $pathToFile, string $pathToDumpFixedFile, StandardParametersData $standardParametersData): Result |
|
22 | { |
||
23 | 3 | $fileContent = file_get_contents($pathToFile); |
|
24 | 3 | $fileContent = str_replace("\r", '', $fileContent); // remove carriage returns |
|
25 | |||
26 | 3 | $rightFileLines = YamlAlphabeticalDataFactory::getCorrectYamlLines($pathToFile, $standardParametersData->getDepth(), $standardParametersData->getAlphabeticalPrioritizedKeys()); |
|
27 | |||
28 | 3 | $rightFileContent = implode("\n", $rightFileLines); |
|
29 | |||
30 | 3 | if ($fileContent === $rightFileContent) { |
|
31 | 1 | return new Result($pathToFile, Result::RESULT_CODE_OK); |
|
32 | } |
||
33 | |||
34 | 2 | file_put_contents($pathToDumpFixedFile, $rightFileContent); |
|
35 | |||
36 | 2 | $differ = new Differ(); |
|
37 | 2 | $diffBetweenStrings = $differ->diff($fileContent, $rightFileContent); |
|
38 | |||
39 | 2 | return new Result($pathToFile, Result::RESULT_CODE_FIXED_INVALID_FILE_SYNTAX, $diffBetweenStrings); |
|
40 | } |
||
42 |