#!/usr/bin/env php [--json] [--output rapport.md]\n"); exit(2); } try { $report = Asm3Analyzer::analyze($source); } catch (Throwable $e) { fwrite(STDERR, "Erreur : {$e->getMessage()}\n"); exit(1); } if ($json) { $content = json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\n"; } else { $a = $report['animals']; $content = "# Rapport de migration ASM3 → Globinours\n\n"; $content .= "Analyse en lecture seule de `{$report['source']}` (" . number_format($report['size_bytes'] / 1048576, 2, ',', ' ') . " Mio). Aucune donnée Globinours n’a été modifiée.\n\n"; $content .= "## Synthèse animale\n\n| Indicateur | Nombre |\n|---|---:|\n"; $content .= '| Total des animaux | ' . ($a['active'] + $a['archived']) . " |\n"; foreach ( [ 'Dossiers actifs dans ASM3' => 'active', 'Dossiers archivés dans ASM3' => 'archived', 'Déclarés adoptables' => 'adoptable', 'Non adoptables' => 'not_adoptable', 'Décédés' => 'deceased', 'Pucés' => 'microchip', 'Tatoués' => 'tattoo', 'Stérilisés' => 'neutered', 'Sans nom' => 'missing_name', 'Sans naissance' => 'missing_birth_date', ] as $label => $key ) { $content .= "| {$label} | {$a[$key]} |\n"; } $content .= "\n## Périmètre de migration\n\n| Domaine ASM3 | Table | Lignes | Cible Globinours | État |\n|---|---|---:|---|---|\n"; foreach ($report['domains'] as $d) { $state = ['ready' => 'Prêt à mapper', 'planned' => 'À implémenter', 'review' => 'À étudier'][$d['status']] ?? $d['status']; $content .= "| {$d['label']} | `{$d['table']}` | {$d['rows']} | `{$d['target']}` | {$state} |\n"; } $content .= "\n## Alertes\n\n" . ($report['warnings'] ? implode("\n", array_map(static fn($w) => '- ' . $w, $report['warnings'])) : '- Aucune anomalie bloquante détectée.') . "\n"; $content .= "\n## Tables non encore mappées\n\n"; foreach (array_slice($report['unmapped_tables'], 0, 30, true) as $table => $count) { $content .= "- `{$table}` : {$count} ligne(s)\n"; } } if ($output) { if (file_put_contents($output, $content) === false) { fwrite(STDERR, "Impossible d’écrire {$output}\n"); exit(1); } fwrite(STDOUT, "Rapport écrit dans {$output}\n"); } else { fwrite(STDOUT, $content); }