Wegen des Formattings nutzen wir Konfiguration in der .editorconfig, das funktioniert ganz gut.
Um die Integrität zu testen bzw. kaputte XML/XLIFF Dateien zu erkennen, hab ich mal ein Script geschrieben, was alle XML/XLIFF Dateien einfach per simplexml_load_file() versucht, zu laden und bei Fehler kaputte Dateien sammelt und ausgibt:
<?php
declare(strict_types=1);
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
function scanLocalDir(string $dir): array
{
$foundXmlFiles = [];
$dir = realpath($dir);
if (is_dir($dir)) {
/** @var array<int, string> $possibleMatches */
$possibleMatches = scandir($dir);
foreach ($possibleMatches as $possibleMatch) {
$fullPath = $dir . '/' . $possibleMatch;
if (is_file($fullPath)) {
if (in_array(pathinfo($fullPath, PATHINFO_EXTENSION), ['xlf', 'xml'])) {
$foundXmlFiles[] = realpath($fullPath);
}
} elseif (!in_array($possibleMatch, ['.', '..', 'Tests']) && is_dir($fullPath)) {
$foundXmlFiles = array_merge(
$foundXmlFiles,
scanLocalDir(
$fullPath
)
);
}
}
}
return $foundXmlFiles;
}
$xmlFiles = array_unique(scanLocalDir(__DIR__ . '/../../packages/'));
$errorFiles = [];
foreach ($xmlFiles as $xmlFile) {
$loadedFile = @simplexml_load_file($xmlFile);
if (!$loadedFile) {
$errorFiles[] = $xmlFile;
}
}
if (count($errorFiles) === 0) {
exit(0);
}
foreach ($errorFiles as $errorFile) {
echo 'Misspelled XML found: ' . $errorFile . PHP_EOL;
}
exit(1);