Skip to content

Commit 2714471

Browse files
authored
Fix PHP 8.4 deprecation: Add explicit nullable type hints (#309)
* Fix PHP 8.4 deprecation: Add explicit nullable type hints Resolves #296 PHP 8.4 deprecates implicitly nullable parameters (e.g., `string $param = null`). This change adds explicit nullable type hints (`?string $param = null`) across the SDK to eliminate deprecation warnings while maintaining backward compatibility with PHP 7.3+. Changes: - Added explicit nullable type hints to all nullable parameters in: - UserManagement, AuditLogs, Organizations, SSO, MFA, Portal, DirectorySync - Client, CurlRequestClient, WebhookResponse - Exception classes (GenericException, BaseRequestException) - Updated RequestClientInterface to match implementation signature - Added tests to verify null parameter handling and backward compatibility - Fixed test expectations to match actual implementation behavior All 167 tests pass. No breaking changes - only type hints added. * Resolved conflicts due to missing changes upstream. Take particular note of the changes to $roleSlugs. There was a mismatch between the phpdoc, tests, and api docs. This commit went with the array due to both the test and api doc specifying the array type. The php doc was updated to reflect the array change.
1 parent 7d88d10 commit 2714471

16 files changed

+370
-117
lines changed

lib/AuditLogs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AuditLogs
3939
*
4040
* @return Resource\AuditLogCreateEventStatus
4141
*/
42-
public function createEvent($organizationId, $event, $idempotencyKey = null)
42+
public function createEvent($organizationId, $event, ?string $idempotencyKey = null)
4343
{
4444
$eventsPath = "audit_logs/events";
4545

@@ -73,7 +73,7 @@ public function createEvent($organizationId, $event, $idempotencyKey = null)
7373
* @return Resource\AuditLogExport
7474
*/
7575

76-
public function createExport($organizationId, $rangeStart, $rangeEnd, $actions = null, $actors = null, $targets = null, $actorNames = null, $actorIds = null)
76+
public function createExport($organizationId, $rangeStart, $rangeEnd, ?array $actions = null, ?array $actors = null, ?array $targets = null, ?array $actorNames = null, ?array $actorIds = null)
7777
{
7878
$createExportPath = "audit_logs/exports";
7979

lib/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function setRequestClient($requestClient)
4646
*
4747
* @return array<string, mixed>
4848
*/
49-
public static function request($method, $path, $headers = null, $params = null, $withAuth = false)
49+
public static function request($method, $path, ?array $headers = null, ?array $params = null, $withAuth = false)
5050
{
5151
$url = self::generateUrl($path);
5252

@@ -105,7 +105,7 @@ public static function generateBaseHeaders($withAuth = false)
105105
*
106106
* @return string
107107
*/
108-
public static function generateUrl($path, $params = null)
108+
public static function generateUrl($path, ?array $params = null)
109109
{
110110
$url = WorkOS::getApiBaseUrl() . $path;
111111

lib/DirectorySync.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class DirectorySync
2727
* @return array{?string, ?string, Resource\Directory[]} An array containing the Directory ID to use as before and after cursor, and an array of Directory instances
2828
*/
2929
public function listDirectories(
30-
$domain = null,
31-
$search = null,
30+
?string $domain = null,
31+
?string $search = null,
3232
$limit = self::DEFAULT_PAGE_SIZE,
33-
$before = null,
34-
$after = null,
35-
$organizationId = null,
36-
$order = null
33+
?string $before = null,
34+
?string $after = null,
35+
?string $organizationId = null,
36+
?string $order = null
3737
) {
3838
$directoriesPath = "directories";
3939
$params = [
@@ -78,12 +78,12 @@ public function listDirectories(
7878
* @return array{?string, ?string, Resource\DirectoryGroup[]} An array containing the Directory Group ID to use as before and after cursor, and an array of Directory Group instances
7979
*/
8080
public function listGroups(
81-
$directory = null,
82-
$user = null,
81+
?string $directory = null,
82+
?string $user = null,
8383
$limit = self::DEFAULT_PAGE_SIZE,
84-
$before = null,
85-
$after = null,
86-
$order = null
84+
?string $before = null,
85+
?string $after = null,
86+
?string $order = null
8787
) {
8888
$groupsPath = "directory_groups";
8989

@@ -156,12 +156,12 @@ public function getGroup($directoryGroup)
156156
* @throws Exception\WorkOSException
157157
*/
158158
public function listUsers(
159-
$directory = null,
160-
$group = null,
159+
?string $directory = null,
160+
?string $group = null,
161161
$limit = self::DEFAULT_PAGE_SIZE,
162-
$before = null,
163-
$after = null,
164-
$order = null
162+
?string $before = null,
163+
?string $after = null,
164+
?string $order = null
165165
) {
166166
$usersPath = "directory_users";
167167

lib/Exception/BaseRequestException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class BaseRequestException extends \Exception implements WorkOSException
2525
* @param Response $response
2626
* @param null|string $message Exception message
2727
*/
28-
public function __construct($response, $message = null)
28+
public function __construct($response, ?string $message = null)
2929
{
3030
$this->response = $response;
3131

lib/Exception/GenericException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class GenericException extends \Exception implements WorkOSException
1717
* @param string $message Exception message
1818
* @param null|array $data Blob
1919
*/
20-
public function __construct($message, $data = null)
20+
public function __construct($message, ?array $data = null)
2121
{
2222
$this->message = $message;
2323

lib/MFA.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ class MFA
2121
*/
2222
public function enrollFactor(
2323
$type,
24-
$totpIssuer = null,
25-
$totpUser = null,
26-
$phoneNumber = null
24+
?string $totpIssuer = null,
25+
?string $totpUser = null,
26+
?string $phoneNumber = null
2727
) {
2828
$enrollPath = "auth/factors/enroll";
2929

@@ -79,7 +79,7 @@ public function enrollFactor(
7979
*/
8080
public function challengeFactor(
8181
$authenticationFactorId,
82-
$smsTemplate = null
82+
?string $smsTemplate = null
8383
) {
8484
if (!isset($authenticationFactorId)) {
8585
$msg = "Incomplete arguments: 'authentication_factor_id' is a required parameter";

lib/Organizations.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class Organizations
2626
* @throws Exception\WorkOSException
2727
*/
2828
public function listOrganizations(
29-
$domains = null,
29+
?array $domains = null,
3030
$limit = self::DEFAULT_PAGE_SIZE,
31-
$before = null,
32-
$after = null,
33-
$order = null
31+
?string $before = null,
32+
?string $after = null,
33+
?string $order = null
3434
) {
3535
$organizationsPath = "organizations";
3636
$params = [
@@ -76,12 +76,12 @@ public function listOrganizations(
7676
*/
7777
public function createOrganization(
7878
$name,
79-
$domains = null,
80-
$allowProfilesOutsideOrganization = null,
81-
$idempotencyKey = null,
82-
$domain_data = null,
83-
$externalId = null,
84-
$metadata = null
79+
?array $domains = null,
80+
?bool $allowProfilesOutsideOrganization = null,
81+
?string $idempotencyKey = null,
82+
?array $domain_data = null,
83+
?string $externalId = null,
84+
?array $metadata = null
8585
) {
8686
$idempotencyKey ? $headers = array("Idempotency-Key: $idempotencyKey") : $headers = null;
8787
$organizationsPath = "organizations";
@@ -126,13 +126,13 @@ public function createOrganization(
126126
*/
127127
public function updateOrganization(
128128
$organization,
129-
$domains = null,
130-
$name = null,
131-
$allowProfilesOutsideOrganization = null,
132-
$domain_data = null,
133-
$stripeCustomerId = null,
134-
$externalId = null,
135-
$metadata = null
129+
?array $domains = null,
130+
?string $name = null,
131+
?bool $allowProfilesOutsideOrganization = null,
132+
?array $domain_data = null,
133+
?string $stripeCustomerId = null,
134+
?string $externalId = null,
135+
?array $metadata = null
136136
) {
137137
$organizationsPath = "organizations/{$organization}";
138138

lib/Portal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Portal
2323
*
2424
* @return Resource\PortalLink
2525
*/
26-
public function generateLink($organization, $intent, $returnUrl = null, $successUrl = null)
26+
public function generateLink($organization, $intent, ?string $returnUrl = null, ?string $successUrl = null)
2727
{
2828
$generateLinkPath = "portal/generate_link";
2929
$params = [

lib/RequestClient/CurlRequestClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CurlRequestClient implements RequestClientInterface
2020
*
2121
* @return array An array composed of the result string, response headers and status code
2222
*/
23-
public function request($method, $url, $headers = null, $params = null)
23+
public function request($method, $url, ?array $headers = null, ?array $params = null)
2424
{
2525
if (empty($headers)) {
2626
$headers = array();

lib/RequestClient/RequestClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ interface RequestClientInterface
1919
*
2020
* @return array An array composed of the result string, response headers and status code
2121
*/
22-
public function request($method, $url, $headers, $params);
22+
public function request($method, $url, ?array $headers = null, ?array $params = null);
2323
}

0 commit comments

Comments
 (0)