#!/usr/bin/env php
<?php

require_once 'vendor/autoload.php';

use Composer\ClassMapGenerator\ClassMapGenerator;
use Deprecated\DeprecatedManager;

if (file_exists(dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . "autoload.php")) {
    $dir = dirname(__DIR__, 3) . $argv[1];
} else {
    $dir = __DIR__ . $argv[1];
}

clearstatcache();

$opt = $argv[2] ?? null;
$dir = str_replace([".\\", "./"], DIRECTORY_SEPARATOR, $dir);

ob_start();

foreach (glob($dir . "*.php") as $filename) {
    require_once $filename;
}

$functions = get_defined_functions()['user'];
$output = ob_get_contents();
ob_end_clean();
unset($output);

$map = [];
$generator = new ClassMapGenerator;
$generator->scanPaths($dir, excludedDirs: ["vendor", ".git"]);
$classMap = $generator->getClassMap();

foreach ($classMap->getMap() as $symbol => $path) {
    $map[$symbol] = $path;
}

DeprecatedManager::checkForDeprecated($map, $functions);