diff --git a/src/Context/BunqContext.php b/src/Context/BunqContext.php index 989eddc6..a7e9f6e0 100644 --- a/src/Context/BunqContext.php +++ b/src/Context/BunqContext.php @@ -39,15 +39,12 @@ public static function loadApiContext(ApiContext $apiContext) /** * @return ApiContext - * @throws BunqException */ public static function getApiContext(): ApiContext { - if (is_null(static::$apiContext)) { - throw new BunqException(self::ERROR_API_CONTEXT_HAS_NOT_BEEN_LOADED); - } else { - return static::$apiContext; - } + static::assertApiContextHasBeenLoaded(); + + return static::$apiContext; } /** @@ -62,4 +59,27 @@ public static function getUserContext(): UserContext return static::$userContext; } } + + /** + * @param ApiContext $apiContext + */ + public static function updateApiContext(ApiContext $apiContext) + { + static::assertApiContextHasBeenLoaded(); + + static::$apiContext = $apiContext; + } + + /** + * @return bool + * @throws BunqException + */ + private static function assertApiContextHasBeenLoaded(): bool + { + if (is_null(static::$apiContext)) { + throw new BunqException(self::ERROR_API_CONTEXT_HAS_NOT_BEEN_LOADED); + } + + return true; + } }