Create new environment detection helper methods

This commit is contained in:
Philipp Stracker 2025-02-03 13:36:45 +01:00
parent 90d2c77a5a
commit 2c35059e4b
No known key found for this signature in database

View file

@ -5,7 +5,7 @@
* @package WooCommerce\PayPalCommerce\WcGateway\Helper
*/
declare(strict_types=1);
declare( strict_types = 1 );
namespace WooCommerce\PayPalCommerce\WcGateway\Helper;
@ -16,20 +16,27 @@ use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
*/
class Environment {
/**
* Name of the production environment.
*/
public const PRODUCTION = 'production';
public const SANDBOX = 'sandbox';
/**
* Name of the sandbox environment.
*/
public const SANDBOX = 'sandbox';
/**
* The Settings.
*
* @var ContainerInterface
*/
private $settings;
private ContainerInterface $settings;
/**
* Environment constructor.
*
* @param ContainerInterface $settings The Settings.
* @param ContainerInterface $settings The settings.
*/
public function __construct( ContainerInterface $settings ) {
$this->settings = $settings;
@ -40,7 +47,7 @@ class Environment {
*
* @return string
*/
public function current_environment(): string {
public function current_environment() : string {
return (
$this->settings->has( 'sandbox_on' ) && $this->settings->get( 'sandbox_on' )
) ? self::SANDBOX : self::PRODUCTION;
@ -53,7 +60,25 @@ class Environment {
*
* @return bool
*/
public function current_environment_is( string $environment ): bool {
public function current_environment_is( string $environment ) : bool {
return $this->current_environment() === $environment;
}
/**
* Returns whether the current environment is sandbox.
*
* @return bool
*/
public function is_sandbox() : bool {
return $this->current_environment_is( self::SANDBOX );
}
/**
* Returns whether the current environment is production.
*
* @return bool
*/
public function is_production() : bool {
return $this->current_environment_is( self::PRODUCTION );
}
}