| 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 |
||
| 22 | 3 | public function fix(string $pathToFile, string $pathToDumpFixedFile, StandardParametersData $standardParametersData): Result |
|
| 23 | { |
||
| 24 | 3 | $fileContent = file_get_contents($pathToFile); |
|
| 25 | 3 | $fileContent = str_replace("\r", '', $fileContent); // remove carriage returns |
|
| 26 | |||
| 27 | 3 | $rightFileLines = YamlAlphabeticalDataFactory::getCorrectYamlLines($pathToFile, $standardParametersData->getDepth(), $standardParametersData->getAlphabeticalPrioritizedKeys()); |
|
| 28 | |||
| 29 | 3 | $rightFileContent = implode("\n", $rightFileLines); |
|
| 30 | |||
| 31 | 3 | if ($fileContent === $rightFileContent) { |
|
| 32 | 1 | return new Result($pathToFile, Result::RESULT_CODE_OK); |
|
| 33 | } |
||
| 34 | |||
| 35 | 2 | file_put_contents($pathToDumpFixedFile, $rightFileContent); |
|
| 36 | |||
| 37 | 2 | $differ = new Differ(new UnifiedDiffOutputBuilder()); |
|
| 38 | 2 | $diffBetweenStrings = $differ->diff($fileContent, $rightFileContent); |
|
| 39 | |||
| 40 | 2 | return new Result($pathToFile, Result::RESULT_CODE_FIXED_INVALID_FILE_SYNTAX, $diffBetweenStrings); |
|
| 41 | } |
||
| 43 |