Skip to content

Commit 90b14d0

Browse files
committed
5
1 parent 0d0bd3a commit 90b14d0

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `whmcs-api` will be documented in this file.
44

5+
## v0.0.5 - 2021-10-27
6+
7+
- refactor to remove return statements in getclientbyphonenumber as return statement might lead to abnormal program termination via the include system
8+
59
## v0.0.4 - 2021-10-27
610

711
- handling of space in telephone numbers

src/getclientbyphonenumber.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
if (!defined("WHMCS"))
1212
die("This file cannot be accessed directly");
1313

14-
try {
14+
try {
1515
// First check for the actual number
1616
$phoneNumber = $_REQUEST['phonenumber'];
1717

@@ -20,40 +20,41 @@
2020
->first();
2121

2222
if ($client) {
23+
2324
$apiresults = [
2425
"result" => "success",
2526
"message" => "ok",
2627
'clientid' => $client->id,
2728
];
2829

29-
return;
30-
}
30+
} else {
31+
// ...then check for the number but without spaces
32+
$phoneNumberWithoutSpaces = str_replace(' ', '', $_REQUEST['phonenumber']);
3133

32-
// ...then check for the number but without spaces
33-
$phoneNumberWithoutSpaces = str_replace(' ', '', $_REQUEST['phonenumber']);
34+
$client = Capsule::table('tblclients')->where("phonenumber", $phoneNumberWithoutSpaces)->first();
3435

35-
$client = Capsule::table('tblclients')->where("phonenumber", $phoneNumberWithoutSpaces)->first();
36+
if ($client) {
37+
$apiresults = [
38+
"result" => "success",
39+
"message" => "ok",
40+
'clientid' => $client->id,
41+
];
3642

37-
if ($client) {
38-
$apiresults = [
39-
"result" => "success",
40-
"message" => "ok",
41-
'clientid' => $client->id,
42-
];
43+
} else {
4344

44-
return;
45+
$apiresults = [
46+
"result" => "error",
47+
"message" => "a client with number $phoneNumber was not found",
48+
];
49+
}
50+
4551
}
4652

47-
$apiresults = [
48-
"result" => "error",
49-
"message" => "a client with number $phoneNumber was not found",
50-
];
51-
53+
5254
} catch (Exception $e) {
5355

5456
$apiresults = [
55-
"result" => "exception",
57+
"result" => "error",
5658
"message" => $e->getMessage(),
5759
];
58-
5960
}

0 commit comments

Comments
 (0)