<?php

$dirs = ['tests', 'database', 'app'];
$files = [];

foreach ($dirs as $dirName) {
    // Note: sail runs in /var/www/html
    if (!is_dir(__DIR__ . '/' . $dirName)) continue;
    $dir = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/' . $dirName));
    foreach ($dir as $file) {
        if ($file->isFile() && $file->getExtension() === 'php') {
            $files[] = $file->getPathname();
        }
    }
}

$replacements = [
    'App\Models\User' => 'App\Models\System\User',
];

foreach ($files as $file) {
    $content = file_get_contents($file);
    $original = $content;

    foreach ($replacements as $old => $new) {
        $content = str_replace($old, $new, $content);
    }

    if ($content !== $original) {
        file_put_contents($file, $content);
        echo "Updated: $file\n";
    }
}
echo "Done.\n";
