From 8b1e59078a0d49a3ff8235ac90f66aefd38076de Mon Sep 17 00:00:00 2001 From: Davo Hynds Date: Mon, 20 Nov 2023 15:18:30 -0600 Subject: [PATCH] Abstract deployment check --- src/LtiMessageLaunch.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/LtiMessageLaunch.php b/src/LtiMessageLaunch.php index 80379a28..3e28aa96 100644 --- a/src/LtiMessageLaunch.php +++ b/src/LtiMessageLaunch.php @@ -178,7 +178,7 @@ public function validate(array $request = null) public function migrate() { if (!$this->shouldMigrate()) { - return $this; + return $this->ensureDeploymentExists(); } if (!isset($this->jwt['body'][LtiConstants::LTI1P1]['oauth_consumer_key_sign'])) { @@ -191,11 +191,7 @@ public function migrate() $this->deployment = $this->db->migrateFromLti1p1($this); - if (!isset($this->deployment)) { - throw new LtiException(static::ERR_NO_DEPLOYMENT); - } - - return $this; + return $this->ensureDeploymentExists(); } public function cacheLaunchData() @@ -522,8 +518,8 @@ protected function validateDeployment(): self $client_id = $this->getAud(); $this->deployment = $this->db->findDeployment($this->jwt['body']['iss'], $this->jwt['body'][LtiConstants::DEPLOYMENT_ID], $client_id); - if (!isset($this->deployment) && !$this->canMigrate()) { - throw new LtiException(static::ERR_NO_DEPLOYMENT); + if (!$this->canMigrate()) { + return $this->ensureDeploymentExists(); } return $this; @@ -573,6 +569,15 @@ private function getAud(): string } } + private function ensureDeploymentExists(): self + { + if (!isset($this->deployment)) { + throw new LtiException(static::ERR_NO_DEPLOYMENT); + } + + return $this; + } + private function canMigrate(): bool { return $this->db instanceof IMigrationDatabase;