Skip to content

Commit f231da2

Browse files
committed
Some refactoring.
1 parent 72180b7 commit f231da2

3 files changed

Lines changed: 24 additions & 57 deletions

File tree

src/Supporting/CommunicationProvider.php

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -420,17 +420,12 @@ public function getDatabaseNames(): array|null
420420
}
421421
$params = ["databases" => null];
422422
$request = [];
423-
try {
424-
$this->callRestAPI($params, false, "GET", $request, $headers, true); // Throw Exception
425-
$this->storeToProperties();
426-
if ($this->httpStatus == 200 && $this->errorCode == 0) {
427-
$returnValue = $this->responseBody->response->databases;
428-
}
429-
} catch (Exception $e) {
430-
throw $e;
431-
} finally {
432-
$this->logout();
423+
$this->callRestAPI($params, false, "GET", $request, $headers, true); // Throw Exception
424+
$this->storeToProperties();
425+
if ($this->httpStatus == 200 && $this->errorCode == 0) {
426+
$returnValue = $this->responseBody->response->databases;
433427
}
428+
$this->logout();
434429
return $returnValue;
435430
}
436431

@@ -446,17 +441,12 @@ public function getLayoutNames(): null|array
446441
$params = ["layouts" => null];
447442
$request = [];
448443
$headers = [];
449-
try {
450-
$this->callRestAPI($params, true, "GET", $request, $headers); // Throw Exception
451-
$this->storeToProperties();
452-
if ($this->httpStatus == 200 && $this->errorCode == 0) {
453-
$returnValue = $this->responseBody->response->layouts;
454-
}
455-
} catch (Exception $e) {
456-
throw $e;
457-
} finally {
458-
$this->logout();
444+
$this->callRestAPI($params, true, "GET", $request, $headers); // Throw Exception
445+
$this->storeToProperties();
446+
if ($this->httpStatus == 200 && $this->errorCode == 0) {
447+
$returnValue = $this->responseBody->response->layouts;
459448
}
449+
$this->logout();
460450
}
461451
return $returnValue;
462452
}
@@ -472,17 +462,12 @@ public function getScriptNames(): null|array
472462
$params = ["scripts" => null];
473463
$request = [];
474464
$headers = [];
475-
try {
476-
$this->callRestAPI($params, true, "GET", $request, $headers); // Throw Exception
477-
$this->storeToProperties();
478-
if ($this->httpStatus == 200 && $this->errorCode == 0) {
479-
$returnValue = $this->responseBody->response->scripts;
480-
}
481-
} catch (Exception $e) {
482-
throw $e;
483-
} finally {
484-
$this->logout();
465+
$this->callRestAPI($params, true, "GET", $request, $headers); // Throw Exception
466+
$this->storeToProperties();
467+
if ($this->httpStatus == 200 && $this->errorCode == 0) {
468+
$returnValue = $this->responseBody->response->scripts;
485469
}
470+
$this->logout();
486471
}
487472
return $returnValue;
488473
}
@@ -897,37 +882,23 @@ private function _json_urlencode(array $value): string
897882

898883
/**
899884
* To create and configure cURL at a single place, avoiding code redundancy.
900-
* If later we need some specific settings for some cases, then add new
901-
* parameters to this function.
902885
*
903-
* @param string|null $url The URL you want to access.
904-
* @param bool $returnTransfer By default, sets CURLOPT_RETURNTRANSFER to `true`.
905-
* But it can be set to false if needed.
886+
* @param string $url The URL you want to access.
906887
* @return CurlHandle
907888
*/
908-
private function _createCurlHandle(string|null $url = null,
909-
bool $returnTransfer = true): CurlHandle
889+
private function _createCurlHandle(string $url): CurlHandle
910890
{
911891
$ch = curl_init();
912-
913-
if (!is_null($url)) {
914-
curl_setopt($ch, CURLOPT_URL, $url);
915-
}
916-
917-
if ($returnTransfer) {
918-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
919-
}
920-
892+
curl_setopt($ch, CURLOPT_URL, $url);
893+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
921894
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
922-
923895
if ($this->isCertValidating) {
924896
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
925897
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
926-
// Use the OS native certificate authorities, if possible.
927-
// This fixes SSL validation errors if `php.ini` doesn't have
928-
// [curl] `curl.cainfo` set properly of if this PEM file isn't
929-
// up to date. Better rely on the OS certificate authorities, which
930-
// is maintained automatically.
898+
/* Use the OS native certificate authorities, if possible.
899+
This fixes SSL validation errors if `php.ini` doesn't have [curl] `curl.cainfo`,
900+
set properly of if this PEM file isn't up to date.
901+
Better rely on the OS certificate authorities, which is maintained automatically. */
931902
if (defined('CURLSSLOPT_NATIVE_CA')
932903
&& version_compare(curl_version()['version'], '7.71', '>=')) {
933904
curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_NATIVE_CA);
@@ -936,11 +907,9 @@ private function _createCurlHandle(string|null $url = null,
936907
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
937908
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
938909
}
939-
940910
if (!is_null($this->timeout)) {
941911
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
942912
}
943-
944913
return $ch;
945914
}
946915
}

src/Supporting/FileMakerLayout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function buildScriptParameters(array|null $param): array
168168
* If $script is array with two elements, these are handled as values of "script" and "layout.response."
169169
* If it's three elements, these are "script", "script.param" and "layout.response."
170170
* If it's four elements, these are "script.prerequest", "script.presort", "script" and "layout.response."
171-
* @param int|null $dateformats; Use this option to specify date formats for date, time, and timestamp fields. The relevant values are: 0 for US, 1 for file locale, or 2 for ISO8601
171+
* @param int|null $dateformats Use this option to specify date formats for date, time, and timestamp fields. The relevant values are: 0 for US, 1 for file locale, or 2 for ISO8601
172172
* @return FileMakerRelation|null Query result.
173173
* @throws Exception In case of any error, an exception arises.
174174
*/

src/Supporting/FileMakerRelation.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ public function toArray(): array
326326
$resultArray[] = $record->toArray();
327327
}
328328
return json_decode(json_encode($resultArray), true);
329-
break;
330329
case 'PORTALRECORD':
331330
if (isset($this->data)) {
332331
return json_decode(json_encode($this->data), true);
@@ -591,7 +590,6 @@ public function valid(): bool
591590
case "RECORD":
592591
case "PORTALRECORD":
593592
return $this->pointer == 0;
594-
break;
595593
}
596594
return false;
597595
}

0 commit comments

Comments
 (0)