Skip to content

Commit

Permalink
Updated code style after review in FBS handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Apr 2, 2024
1 parent 26644f4 commit 4c5d2f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions modules/os2forms_fbs_handler/os2forms_fbs_handler.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
24 changes: 13 additions & 11 deletions modules/os2forms_fbs_handler/src/Client/FBS.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -19,6 +19,8 @@ final class FBS {
*/
private string $sessionKey;

private const authenticateStatusValid = 'VALID';

/**
* Default constructor.
*/
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);

Expand All @@ -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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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])],
],
];
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4c5d2f0

Please sign in to comment.