Skip to content

Update deprecation notices #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8b9221f
Improve Webhook and BaseWorkOSResource PHPDoc types
Mar 11, 2025
8988129
Enhance Webhook class with improved code style and PHPDoc annotations
Mar 11, 2025
6573b8e
Merge branch 'main' into ide-improvements
Mar 15, 2025
92bc0c6
Add accessToken and refreshToken to AuthenticationResponse class
Mar 15, 2025
eb67567
Update AuthenticationResponse class to include organizationId as null…
Mar 15, 2025
0c5672a
Enhance OrganizationMembership class with additional PHPDoc propertie…
Mar 15, 2025
ff55574
Add metadata and external id (#268)
ericroberts Mar 21, 2025
09c8949
Add email standard attribute to DirectoryUser and mark deprecated sta…
mattgd Mar 21, 2025
829e418
Add function to get organization by external id (#270)
ericroberts Mar 21, 2025
f2d7f7b
Add support for creating, getting and updating users with external_id…
pepeloper Mar 21, 2025
d366c83
Bump to version 4.22.0. (#269)
mattgd Mar 21, 2025
1ec12f4
Structured responses to webhook events (#265)
bradenkeith Mar 21, 2025
7381751
Merge branch 'workos:main' into ide-improvements
bradenkeith Mar 28, 2025
19e68d1
Update deprecation notices in DirectoryUser class to include version …
Mar 28, 2025
52dc0ba
Update deprecation notices in Organizations class to include version …
Mar 28, 2025
b25b57d
Update doc blocks for deprecation notices
Mar 28, 2025
053ff55
Update tests to expect Role Slug
Mar 28, 2025
d19ee79
Refactor deprecation handling across multiple classes to use trigger_…
Mar 28, 2025
2646568
Implement deprecation warnings for 'domains' and 'allowProfilesOutsid…
Mar 28, 2025
a621976
Update deprecation notice for 'allowProfilesOutsideOrganization' in O…
Mar 28, 2025
a445265
Update deprecation messages across multiple classes to ensure consist…
Mar 28, 2025
1507906
IDE & Typehint improvements (#264)
bradenkeith Apr 2, 2025
c31d9dc
Enhance Webhook class with improved code style and PHPDoc annotations
Mar 11, 2025
99975bd
Add metadata and external id (#268)
ericroberts Mar 21, 2025
838f26f
Add email standard attribute to DirectoryUser and mark deprecated sta…
mattgd Mar 21, 2025
84b072b
Add support for creating, getting and updating users with external_id…
pepeloper Mar 21, 2025
5cda751
Improve code style across multiple test classes.
Apr 3, 2025
966ca0c
Merge branch 'main' into update-deprecation-notices
bradenkeith Apr 3, 2025
4953224
Remove unnecessary blank line in UserManagementTest.php following dep…
Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/AuditLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public function createExport($organizationId, $rangeStart, $rangeEnd, $actions =
};

if (!is_null($actors)) {
$msg = "'actors' is deprecated. Please use 'actorNames' instead'";
$msg = "'actors' is deprecated. Please use 'actorNames' instead.";

error_log($msg);
trigger_error($msg, E_USER_DEPRECATED);

$params["actors"] = $actors;
};
Expand Down
30 changes: 15 additions & 15 deletions lib/MFA.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public function enrollFactor(
$enrollPath = "auth/factors/enroll";

if (!isset($type)) {
$msg = "Incomplete arguments: Need to specify a type of factor";
$msg = "Incomplete arguments: Need to specify a type of factor.";
throw new Exception\UnexpectedValueException($msg);
}

if ($type != "sms" && $type != "totp") {
$msg = "Type Parameter must either be 'sms' or 'totp'";
$msg = "Type Parameter must either be 'sms' or 'totp'.";
throw new Exception\UnexpectedValueException($msg);
}

Expand Down Expand Up @@ -82,15 +82,15 @@ public function challengeFactor(
$smsTemplate = null
) {
if (!isset($authenticationFactorId)) {
$msg = "Incomplete arguments: 'authentication_factor_id' is a required parameter";
$msg = "Incomplete arguments: 'authentication_factor_id' is a required parameter.";
throw new Exception\UnexpectedValueException($msg);
}

$challengePath = "auth/factors/{$authenticationFactorId}/challenge";

$params = [
"sms_template" => $smsTemplate
];
"sms_template" => $smsTemplate
];

$response = Client::request(
Client::METHOD_POST,
Expand Down Expand Up @@ -120,19 +120,19 @@ public function verifyFactor(
$code
) {
if (!isset($authenticationChallengeId) || !isset($code)) {
$msg = "Incomplete arguments: 'authenticationChallengeId' and 'code' are required parameters";
$msg = "Incomplete arguments: 'authenticationChallengeId' and 'code' are required parameters.";
throw new Exception\UnexpectedValueException($msg);
}

$msg = "'verifyFactor' is deprecated. Please use 'verifyChallenge' instead";
$msg = "'verifyFactor' is deprecated. Please use 'verifyChallenge' instead.";

error_log($msg);
trigger_error($msg, E_USER_DEPRECATED);

$response = (new \WorkOS\MFA())
->verifyChallenge(
$authenticationChallengeId,
$code
);
->verifyChallenge(
$authenticationChallengeId,
$code
);

return $response;
}
Expand All @@ -151,15 +151,15 @@ public function verifyChallenge(
$code
) {
if (!isset($authenticationChallengeId) || !isset($code)) {
$msg = "Incomplete arguments: 'authenticationChallengeId' and 'code' are required parameters";
$msg = "Incomplete arguments: 'authenticationChallengeId' and 'code' are required parameters.";
throw new Exception\UnexpectedValueException($msg);
}

$verifyPath = "auth/challenges/{$authenticationChallengeId}/verify";

$params = [
"code" => $code
];
"code" => $code
];

$response = Client::request(
Client::METHOD_POST,
Expand Down
16 changes: 16 additions & 0 deletions lib/Organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,20 @@ public function createOrganization(
$params = ["name" => $name];

if (isset($domains)) {
$msg = "'domains' is deprecated. Please use 'domain_data' instead.";

trigger_error($msg, E_USER_DEPRECATED);

$params["domains"] = $domains;
}
if (isset($domain_data)) {
$params["domain_data"] = $domain_data;
}
if (isset($allowProfilesOutsideOrganization)) {
$msg = "'allowProfilesOutsideOrganization' is deprecated. If you need to allow sign-ins from any email domain, contact [email protected].";

trigger_error($msg, E_USER_DEPRECATED);

$params["allow_profiles_outside_organization"] = $allowProfilesOutsideOrganization;
}
if (isset($externalId)) {
Expand Down Expand Up @@ -139,12 +147,20 @@ public function updateOrganization(
$params = ["name" => $name];

if (isset($domains)) {
$msg = "'domains' is deprecated. Please use 'domain_data' instead.";

trigger_error($msg, E_USER_DEPRECATED);

$params["domains"] = $domains;
}
if (isset($domain_data)) {
$params["domain_data"] = $domain_data;
}
if (isset($allowProfilesOutsideOrganization)) {
$msg = "'allowProfilesOutsideOrganization' is deprecated. If you need to allow sign-ins from any email domain, contact [email protected].";

trigger_error($msg, E_USER_DEPRECATED);

$params["allow_profiles_outside_organization"] = $allowProfilesOutsideOrganization;
}
if (isset($stripeCustomerId)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Resource/BaseWorkOSResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __set($key, $value)
$this->values[$key] = $value;
}

$msg = "{$key} does not exist on " . static::class;
$msg = "{$key} does not exist on " . static::class . ".";
throw new \WorkOS\Exception\UnexpectedValueException($msg);
}

Expand All @@ -100,7 +100,7 @@ public function &__get($key)
return $this->raw[$key];
}

$msg = "{$key} does not exist on " . static::class;
$msg = "{$key} does not exist on " . static::class . ".";
throw new \WorkOS\Exception\UnexpectedValueException($msg);
}
}
4 changes: 4 additions & 0 deletions lib/Resource/DirectoryUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class DirectoryUser extends BaseWorkOSResource
*/
public function primaryEmail()
{
$msg = "'primaryEmail' is deprecated. Please use 'email' instead.";

trigger_error($msg, E_USER_DEPRECATED);

$response = $this;

if (count($response->raw["emails"]) == 0) {
Expand Down
6 changes: 3 additions & 3 deletions lib/SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public function getAuthorizationUrl(
$authorizationPath = "sso/authorize";

if (!isset($domain) && !isset($provider) && !isset($connection) && !isset($organization)) {
$msg = "Either \$domain, \$provider, \$connection, or \$organization is required";
$msg = "Either \$domain, \$provider, \$connection, or \$organization is required.";

throw new Exception\UnexpectedValueException($msg);
}

if (isset($domain)) {
$msg = "Domain is being deprecated, please switch to using Connection or Organization ID";
$msg = "'domain' is being deprecated, please switch to using 'connection' or 'organization'.";

error_log($msg);
trigger_error($msg, E_USER_DEPRECATED);
}

$params = [
Expand Down
15 changes: 7 additions & 8 deletions lib/UserManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class UserManagement
*
* @return Resource\User
*/

public function createUser(
$email,
$password = null,
Expand Down Expand Up @@ -627,7 +626,7 @@ public function getAuthorizationUrl(
$path = "user_management/authorize";

if (!isset($provider) && !isset($connectionId) && !isset($organizationId)) {
$msg = "Either \$provider, \$connectionId, or \$organizationId is required";
$msg = "Either \$provider, \$connectionId, or \$organizationId is required.";
throw new Exception\UnexpectedValueException($msg);
}

Expand All @@ -640,7 +639,7 @@ public function getAuthorizationUrl(
];

if (isset($provider) && !\in_array($provider, $supportedProviders)) {
$msg = "Only " . implode("','", $supportedProviders) . " providers are supported";
$msg = "Only " . implode("','", $supportedProviders) . " providers are supported.";
throw new Exception\UnexpectedValueException($msg);
}

Expand Down Expand Up @@ -1110,7 +1109,7 @@ public function sendPasswordResetEmail($email, $passwordResetUrl)
{
$msg = "'sendPasswordResetEmail' is deprecated. Please use 'createPasswordReset' instead. This method will be removed in a future major version.";

error_log($msg);
trigger_error($msg, E_USER_DEPRECATED);

$path = "user_management/password_reset/send";

Expand Down Expand Up @@ -1224,7 +1223,7 @@ public function sendMagicAuthCode($email)

$msg = "'sendMagicAuthCode' is deprecated. Please use 'createMagicAuth' instead. This method will be removed in a future major version.";

error_log($msg);
trigger_error($msg, E_USER_DEPRECATED);

$response = Client::request(
Client::METHOD_POST,
Expand Down Expand Up @@ -1261,17 +1260,17 @@ public function getJwksUrl(string $clientId)
* Returns the logout URL to end a user's session and redirect to your home page.
*
* @param string $sessionId The session ID of the user.
* @param string $return_to The URL to redirect to after the user logs out.
* @param string|null $return_to The URL to redirect to after the user logs out.
*
* @return string
*/
public function getLogoutUrl(string $sessionId, string $return_to = null)
public function getLogoutUrl(string $sessionId, ?string $return_to = null)
{
if (!isset($sessionId) || empty($sessionId)) {
throw new Exception\UnexpectedValueException("sessionId must not be empty");
}

$params = [ "session_id" => $sessionId ];
$params = ["session_id" => $sessionId];
if ($return_to) {
$params["return_to"] = $return_to;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/WorkOS.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function getApiKey()
return self::$apiKey;
}

$msg = "\$apiKey is required";
$msg = "\$apiKey is required.";
throw new \WorkOS\Exception\ConfigurationException($msg);
}

Expand Down Expand Up @@ -76,7 +76,7 @@ public static function getClientId()
return self::$clientId;
}

$msg = "\$clientId is required";
$msg = "\$clientId is required.";
throw new \WorkOS\Exception\ConfigurationException($msg);
}

Expand Down
6 changes: 4 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<phpunit bootstrap="tests/bootstrap.php" colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="WorkOS PHP Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
</phpunit>
39 changes: 39 additions & 0 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@

namespace WorkOS;

use WorkOS\Client;

trait TestHelper
{
/**
* @var \WorkOS\RequestClient\RequestClientInterface
*/
protected $defaultRequestClient;

/**
* @var \PHPUnit\Framework\MockObject\MockObject
*/
protected $requestClientMock;

protected function setUp(): void
Expand Down Expand Up @@ -106,4 +115,34 @@ private function prepareRequestMock($method, $url, $headers, $params)
static::identicalTo($params)
);
}

/**
* Asserts that a specific deprecation warning is triggered when callable is executed
*
* @param string $expected_warning The expected deprecation message
* @param callable $callable The function or method that should trigger the deprecation
* @return mixed The return value from the callable
*/
protected function assertDeprecationTriggered(string $expected_warning, callable $callable)
{
$caught = false;

set_error_handler(function ($errno, $errstr) use ($expected_warning, &$caught) {
if ($errno === E_USER_DEPRECATED && $errstr === $expected_warning) {
$caught = true;
return true;
}
return false;
});

$result = $callable();

restore_error_handler();

if (!$caught) {
$this->fail('Expected deprecation warning was not triggered: ' . $expected_warning);
}

return $result;
}
}
Loading