<?php

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

header('Content-Type: text/plain; charset=utf-8');

$root = dirname(__DIR__);

$checks = [
    'app/helpers.php' => [
        'function app_base_path(): string',
        'return app_base_path()',
    ],
    'public/index.php' => [
        '$basePath = app_base_path();',
        'strpos($path, $basePath) === 0',
    ],
    'resources/views/layouts/header.php' => [
        "url('/assets/css/app.css",
    ],
];

echo "Locative files check\n";
echo "====================\n\n";

foreach ($checks as $relativePath => $needles) {
    $path = $root . '/' . $relativePath;
    echo $relativePath . ': ';

    if (!is_file($path)) {
        echo "MISSING\n";
        continue;
    }

    $content = file_get_contents($path);
    $missing = [];

    foreach ($needles as $needle) {
        if (strpos($content, $needle) === false) {
            $missing[] = $needle;
        }
    }

    if ($missing) {
        echo "OLD OR NOT UPDATED\n";
        foreach ($missing as $needle) {
            echo "  missing: " . $needle . "\n";
        }
        continue;
    }

    echo "OK\n";
}

echo "\nDone.\n";
