<?php

namespace Helpers\Framework;

class Debug
{
    /**
     * @param bool $die
     * @param string $fct
     * @param mixed $vars
     * @return void
     */
    public static function show(bool $die, string $fct, ...$vars): void
    {
        if ($fct === '@var_dump' || $fct === '@print_r') {
            $fct = str_replace('@', '', $fct);
            echo '<pre>';
            foreach ($vars as $var) {
                /** @phpstan-ignore-next-line */
                $fct($var);
            }
            echo '</pre>';
            if ($die) {
                die;
            }
        }
    }

    /**
     * @param mixed $vars
     * @return void
     */
    public static function dieError(...$vars): void
    {
        self::show(true, '@var_dump', ...$vars);
    }
    
    /**
     * @param int $client
     * @param bool $die
     * @param mixed $vars
     * @return void
     */
    public static function debugClient(int $client, bool $die, ...$vars):void
    {
        if ($_SESSION['Session_NumClient'] == $client) {
            foreach ($vars as $var) {
                @var_dump($var);
            }

            if ($die) {
                die;
            }
        }
    }
}
