<?php

namespace Tricks\NovaPhpInformationCard;

use Laravel\Nova\Card;

class NovaPhpInformationCard extends Card
{
    /**
     * The width of the card (1/3, 1/2, or full).
     *
     * @var string
     */
    public $width = '1/3';

    public function __construct()
    {
        parent::__construct();
        $this->withMeta(['opcacheIsActive' => self::opcacheIsActive()]);
        $this->withMeta(['xdebugIsActive' => self::xdebugIsActive()]);
        $this->withMeta(['php_version' => phpversion()]);
    }

    private static function opcacheIsActive(): bool
    {
        if (! function_exists('opcache_get_status')) {
            return false;
        }

        return is_array(opcache_get_status());
    }

    private static function xdebugIsActive(): bool
    {
        return extension_loaded('xdebug');
    }

    public function component(): string
    {
        return 'opcache-status';
    }
}
