From 4c5d2f0c159bae10c21192580a73fb959b0ff306 Mon Sep 17 00:00:00 2001 From: Jesper Kristensen Date: Thu, 21 Mar 2024 11:14:11 +0100 Subject: [PATCH] Updated code style after review in FBS handler --- composer.json | 1 - .../os2forms_fbs_handler.info.yml | 3 +-- .../os2forms_fbs_handler/src/Client/FBS.php | 24 ++++++++++--------- .../WebformHandler/FbsWebformHandler.php | 8 +++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 9e4b38da..50d3d8f6 100644 --- a/composer.json +++ b/composer.json @@ -71,7 +71,6 @@ "drupal/webform_validation": "^2.0", "drupal/webform_views": "^5.0@alpha", "drupal/workflow_participants": "^2.4", - "fig/http-message-util": "^1.1", "http-interop/http-factory-guzzle": "^1.0.0", "itk-dev/beskedfordeler-drupal": "^1.0", "itk-dev/serviceplatformen": "dev-feature/guzzle6-adapter as 1.5", diff --git a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml index d2a16222..53bba305 100644 --- a/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml +++ b/modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml @@ -2,8 +2,7 @@ name: 'FBS Handler' type: module description: 'Provides integration to FBS.' package: 'OS2Forms' -core: 8.x -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8.8 || ^9 dependencies: - 'webform:webform' - 'advancedqueue:advancedqueue' diff --git a/modules/os2forms_fbs_handler/src/Client/FBS.php b/modules/os2forms_fbs_handler/src/Client/FBS.php index f628ee87..7a785852 100644 --- a/modules/os2forms_fbs_handler/src/Client/FBS.php +++ b/modules/os2forms_fbs_handler/src/Client/FBS.php @@ -4,13 +4,13 @@ use Drupal\os2forms_fbs_handler\Client\Model\Guardian; use Drupal\os2forms_fbs_handler\Client\Model\Patron; -use Fig\Http\Message\RequestMethodInterface; +use Symfony\Component\HttpFoundation\Request; use GuzzleHttp\Client; /** * Minimalistic client to create user with guardians at FBS. */ -final class FBS { +class FBS { /** * FBS session key. @@ -19,6 +19,8 @@ final class FBS { */ private string $sessionKey; + private const authenticateStatusValid = 'VALID'; + /** * Default constructor. */ @@ -32,7 +34,7 @@ public function __construct( } /** - * Login to FBS and obtain session key. + * Login to FBS and obtain a session key. * * @return bool * TRUE on success else FALSE. @@ -80,14 +82,14 @@ public function isLoggedIn(): bool { * @throws \JsonException */ public function doUserExists(string $cpr): ?Patron { - // Check if session have been created with FBS and if not create it. + // Check if session has been created with FBS and if not creates it. if (!$this->isLoggedIn()) { $this->login(); } // Try pre-authenticate the user/parent. $json = $this->request('/external/{agency_id}/patrons/preauthenticated/v9', $cpr); - if ($json->authenticateStatus === 'VALID') { + if ($json->authenticateStatus === $this::authenticateStatusValid) { return new Patron( $json->patron->patronId, (bool) $json->patron->receiveSms, @@ -157,9 +159,9 @@ public function updatePatron(Patron $patron): bool { ], ]; - $json = $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + $json = $this->request($uri, $payload, Request::METHOD_PUT); - return $json->authenticateStatus === 'VALID'; + return $json->authenticateStatus === $this::authenticateStatusValid; } /** @@ -183,7 +185,7 @@ public function createGuardian(Patron $patron, Guardian $guardian): int { 'guardian' => $guardian->toArray(), ]; - return $this->request($uri, $payload, RequestMethodInterface::METHOD_PUT); + return $this->request($uri, $payload, Request::METHOD_PUT); } /** @@ -202,7 +204,7 @@ public function createGuardian(Patron $patron, Guardian $guardian): int { * @throws \GuzzleHttp\Exception\GuzzleException * @throws \JsonException */ - private function request(string $uri, array|string $data, string $method = RequestMethodInterface::METHOD_POST): mixed { + private function request(string $uri, array|string $data, string $method = Request::METHOD_POST): mixed { $url = rtrim($this->endpoint, '/\\'); $url = $url . str_replace('{agency_id}', $this->agencyId, $uri); @@ -212,7 +214,7 @@ private function request(string $uri, array|string $data, string $method = Reque ], ]; - // The API designer at FBS don't always use JSON. So in some cases only a + // The API designer at FBS doesn't always use JSON. So in some cases only a // string should be sent. if (is_array($data)) { $options['json'] = $data; @@ -221,7 +223,7 @@ private function request(string $uri, array|string $data, string $method = Reque $options['body'] = $data; } - // If already logged in lets add the session key to the request headers. + // If already logged in, lets add the session key to the request headers. if ($this->isLoggedIn()) { $options['headers']['X-Session'] = $this->sessionKey; } diff --git a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php index e201d2d0..c6654f81 100644 --- a/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php +++ b/modules/os2forms_fbs_handler/src/Plugin/WebformHandler/FbsWebformHandler.php @@ -40,10 +40,8 @@ final class FbsWebformHandler extends WebformHandlerBase { /** * The queue id. - * - * @var string */ - private string $queueId = 'os2forms_fbs_handler'; + private const queueId = 'os2forms_fbs_handler'; /** * Constructs an FbsWebformHandler object. @@ -95,7 +93,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta $form['queue_message'] = [ '#theme' => 'status_messages', '#message_list' => [ - 'warning' => [$this->t('Cannot get queue @queue_id', ['@queue_id' => $this->queueId])], + 'warning' => [$this->t('Cannot get queue @queue_id', ['@queue_id' => $this::queueId])], ], ]; } @@ -204,7 +202,7 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update private function getQueue(): ?Queue { $queueStorage = $this->entityTypeManager->getStorage('advancedqueue_queue'); /** @var ?\Drupal\advancedqueue\Entity\Queue $queue */ - $queue = $queueStorage->load($this->queueId); + $queue = $queueStorage->load($this::queueId); return $queue; }