$line) {
$originalLine = $line;
$trimmed = trim($line);
if (!(str_starts_with($trimmed, '{') && str_ends_with($trimmed, '}'))) {
continue;
}
foreach ($debugKeys as $key) {
if (
strpos($line, '
') !== false &&
strpos($line, $key) !== false &&
strpos($line, '$' . $key) !== false
) {
$totalAnalyzed++;
$nbDollar = preg_match_all('/\$[a-zA-Z0-9_]+/', $line, $matches);
if ($nbDollar > 1) {
$log[] = "[IGNORÉ] $filePath:" . ($i + 1) . "\nLigne : $originalLine";
continue;
}
$newLine = "\t{\$debugMsg .= monDebug(2,['$key' => \$$key],'$filename');}\n";
$log[] = ($simulation ? "[SIMULATION]" : "[MODIFIÉ]") . " $filePath:" . ($i + 1)
. "\nAncienne : $originalLineNouvelle : $newLine";
if (!$simulation) {
$lines[$i] = $newLine;
$changed = true;
$totalModified++;
$modifiedFiles[$filePath] = true;
}
break;
}
}
}
if (!$simulation && $changed) {
file_put_contents($filePath, implode('', $lines));
}
}
function scanDirectory($dir, $excludedDirs, $debugKeys, $simulation, &$log, &$totalAnalyzed, &$totalModified, &$modifiedFiles) {
$iterator = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
function ($file, $key, $iterator) use ($excludedDirs) {
$path = $file->getPathname();
return !isExcluded($path, $excludedDirs);
}
)
);
foreach ($iterator as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
processFile($file->getPathname(), $debugKeys, $simulation, $log, $totalAnalyzed, $totalModified, $modifiedFiles);
}
}
}
// === LANCEMENT ===
scanDirectory(ROOT_DIR, $excludedDirs, $debugKeys, $simulation, $log, $totalAnalyzed, $totalModified, $modifiedFiles);
// === LOG FINAL ===
$duration = round(microtime(true) - $startTime, 2);
$summary = "\n--- Résumé ---\n"
. "Mode : " . ($simulation ? "Simulation" : "Traitement réel") . "\n"
. "Lignes analysées : $totalAnalyzed\n"
. "Lignes modifiées : $totalModified\n"
. "Fichiers modifiés : " . count($modifiedFiles) . "\n"
. "Durée : {$duration}s\n";
$log[] = $summary;
file_put_contents($logFile, implode("\n", $log));
echo $summary;
?>