From 2c35059e4bdb336f283e2050232f3db70bfe3e98 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Mon, 3 Feb 2025 13:36:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Create=20new=20environment=20detect?= =?UTF-8?q?ion=20helper=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Helper/Environment.php | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-wc-gateway/src/Helper/Environment.php b/modules/ppcp-wc-gateway/src/Helper/Environment.php index 9c4599333..a603e9179 100644 --- a/modules/ppcp-wc-gateway/src/Helper/Environment.php +++ b/modules/ppcp-wc-gateway/src/Helper/Environment.php @@ -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 ); + } }