<?php

namespace ProudNerds\Trait;

/**
 * Make class a singleton.
 */
trait Singleton
{
    /**
     * The instance of the class.
     *
     * @var static|null
     */
    private static ?self $instance = null;

    /**
     * Private constructor.
     */
    private function __construct()
    {
    }

    /**
     * Prevent cloning of the instance.
     */
    private function __clone()
    {
    }

    /**
     * Get the instance of the class.
     *
     * @return static
     */
    public static function getInstance(): static
    {
        if (null === self::$instance) {
            self::$instance = new static();
        }

        return self::$instance;
    }
}
