<?php
/**
 * Global configuration class.
 *
 * @package Awesomemotive\Rewardswp
 * @since 1.0.0
 */

namespace Awesomemotive\Rewardswp;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use wpdb;

/**
 * Class GlobalConfig
 *
 * This class provides a layer to encapsulate global WordPress variables like $wpdb and $phpmailer.
 * Encapsulating globals in dedicated methods offers several key benefits:
 *
 * - Improved Clarity: Provides explicit methods that make code more readable and easier to understand.
 * - Encapsulation: Allows for additional logic, validation, or processing to be added in a single place.
 * - Testability: Facilitates mocking dependencies during testing, making the code more modular and easier to maintain.
 * - Reduced Coupling: Helps reduce direct reliance on `$GLOBALS`, creating a more flexible and maintainable architecture.
 *
 * By providing dedicated getter methods, this class abstracts away the reliance on globals, enabling better maintainability
 * and making it easier to refactor or replace the global dependencies in the future if necessary.
 *
 * @since 1.0.0
 */
class GlobalConfig {

	/**
	 * Get the database instance.
	 *
	 * @since 1.0.0
	 *
	 * @return wpdb|null
	 */
	public function get_db(): ?wpdb {
		global $wpdb;
		return $wpdb ?? null;
	}

	/**
	 * Get the mailer instance.
	 *
	 * @since 1.0.0
	 *
	 * @return mixed|null
	 */
	public function get_mailer() {
		global $phpmailer;
		return $phpmailer ?? null;
	}
}
