Skip to content

Commit

Permalink
Fix PHP CS Fixer errors (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein authored Feb 24, 2025
1 parent 11a6224 commit 3d18ab2
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 332 deletions.
26 changes: 13 additions & 13 deletions src/ConfigCatClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ public function getValue(string $key, mixed $defaultValue, ?User $user = null):
$settingsResult->fetchTime
)->getValue();
} catch (Throwable $exception) {
$message = "Error occurred in the `getValue` method while evaluating setting '".$key."'. ".
'Returning the `defaultValue` parameter that you specified '.
"in your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$message = "Error occurred in the `getValue` method while evaluating setting '".$key."'. "
.'Returning the `defaultValue` parameter that you specified '
."in your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$messageCtx = [
'event_id' => 1002, 'exception' => $exception,
];
Expand Down Expand Up @@ -228,9 +228,9 @@ public function getValueDetails(string $key, mixed $defaultValue, ?User $user =

return $this->evaluate($key, $settingsResult->settings, $defaultValue, $user, $settingsResult->fetchTime);
} catch (Throwable $exception) {
$message = "Error occurred in the `getValueDetails` method while evaluating setting '".$key."'. ".
'Returning the `defaultValue` parameter that you specified in '.
"your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$message = "Error occurred in the `getValueDetails` method while evaluating setting '".$key."'. "
.'Returning the `defaultValue` parameter that you specified in '
."your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$messageCtx = [
'event_id' => 1002, 'exception' => $exception,
];
Expand Down Expand Up @@ -461,9 +461,9 @@ private function checkSettingsAvailable(SettingsResult $settingsResult, string $
private function checkSettingAvailable(SettingsResult $settingsResult, string $key, mixed $defaultValue): ?string
{
if (!$settingsResult->hasConfigJson) {
$message = "Config JSON is not present when evaluating setting '".$key."'. ".
'Returning the `defaultValue` parameter that you specified in '.
"your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$message = "Config JSON is not present when evaluating setting '".$key."'. "
.'Returning the `defaultValue` parameter that you specified in '
."your application: '".Utils::getStringRepresentation($defaultValue)."'.";
$messageCtx = [
'event_id' => 1000,
];
Expand All @@ -473,10 +473,10 @@ private function checkSettingAvailable(SettingsResult $settingsResult, string $k
}

if (!array_key_exists($key, $settingsResult->settings)) {
$message = "Failed to evaluate setting '".$key."' (the key was not found in config JSON). ".
'Returning the `defaultValue` parameter that you specified in your '.
"application: '".Utils::getStringRepresentation($defaultValue)."'. ".
'Available keys: ['.(!empty($settingsResult->settings) ? "'".implode("', '", array_keys($settingsResult->settings))."'" : '').'].';
$message = "Failed to evaluate setting '".$key."' (the key was not found in config JSON). "
.'Returning the `defaultValue` parameter that you specified in your '
."application: '".Utils::getStringRepresentation($defaultValue)."'. "
.'Available keys: ['.(!empty($settingsResult->settings) ? "'".implode("', '", array_keys($settingsResult->settings))."'" : '').'].';
$messageCtx = [
'event_id' => 1001,
];
Expand Down
16 changes: 8 additions & 8 deletions src/ConfigFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ private function executeFetch(?string $etag, string $url, int $executionCount):

if (RedirectMode::SHOULD == $redirect) {
$this->logger->warning(
'The `dataGovernance` parameter specified at the client initialization is '.
'not in sync with the preferences on the ConfigCat Dashboard. '.
'Read more: https://configcat.com/docs/advanced/data-governance/',
'The `dataGovernance` parameter specified at the client initialization is '
.'not in sync with the preferences on the ConfigCat Dashboard. '
.'Read more: https://configcat.com/docs/advanced/data-governance/',
[
'event_id' => 3002,
]
Expand Down Expand Up @@ -178,18 +178,18 @@ private function sendConfigFetchRequest(?string $etag, string $url): FetchRespon
return FetchResponse::notModified();
}

$message = 'Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey. '.
"Received unexpected response: {$statusCode}";
$message = 'Your SDK Key seems to be wrong. You can find the valid SDK Key at https://app.configcat.com/sdkkey. '
."Received unexpected response: {$statusCode}";
$messageCtx = [
'event_id' => 1100,
];
$this->logger->error($message, $messageCtx);

return FetchResponse::failure(InternalLogger::format($message, $messageCtx));
} catch (ClientExceptionInterface $exception) {
$message = 'Unexpected error occurred while trying to fetch config JSON. '.
'It is most likely due to a local network issue. '.
'Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.';
$message = 'Unexpected error occurred while trying to fetch config JSON. '
.'It is most likely due to a local network issue. '
.'Please make sure your application can reach the ConfigCat CDN servers (or your proxy server) over HTTP.';
$messageCtx = ['event_id' => 1103, 'exception' => $exception];
$this->logger->error($message, $messageCtx);

Expand Down
34 changes: 17 additions & 17 deletions src/RolloutEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,44 +1181,44 @@ private function getUserAttributeValueAsStringArray(string $attributeName, mixed

private function logUserObjectIsMissing(string $key): void
{
$this->logger->warning("Cannot evaluate targeting rules and % options for setting '{$key}' (User Object is missing). ".
'You should pass a User Object to the evaluation methods like `getValue()` in order to make targeting work properly. '.
'Read more: https://configcat.com/docs/advanced/user-object/', [
$this->logger->warning("Cannot evaluate targeting rules and % options for setting '{$key}' (User Object is missing). "
.'You should pass a User Object to the evaluation methods like `getValue()` in order to make targeting work properly. '
.'Read more: https://configcat.com/docs/advanced/user-object/', [
'event_id' => 3001,
]);
}

private function logUserObjectAttributeIsMissingPercentage(string $key, string $attributeName): void
{
$this->logger->warning("Cannot evaluate % options for setting '{$key}' (the User.{$attributeName} attribute is missing). ".
"You should set the User.{$attributeName} attribute in order to make targeting work properly. ".
'Read more: https://configcat.com/docs/advanced/user-object/', [
$this->logger->warning("Cannot evaluate % options for setting '{$key}' (the User.{$attributeName} attribute is missing). "
."You should set the User.{$attributeName} attribute in order to make targeting work properly. "
.'Read more: https://configcat.com/docs/advanced/user-object/', [
'event_id' => 3003,
]);
}

private function logUserObjectAttributeIsMissingCondition(string $condition, string $key, string $attributeName): void
{
$this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' (the User.{$attributeName} attribute is missing). ".
"You should set the User.{$attributeName} attribute in order to make targeting work properly. ".
'Read more: https://configcat.com/docs/advanced/user-object/', [
$this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' (the User.{$attributeName} attribute is missing). "
."You should set the User.{$attributeName} attribute in order to make targeting work properly. "
.'Read more: https://configcat.com/docs/advanced/user-object/', [
'event_id' => 3003,
]);
}

private function logUserObjectAttributeIsInvalid(string $condition, string $key, string $reason, string $attributeName): void
{
$this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' ({$reason}). ".
"Please check the User.{$attributeName} attribute and make sure that its value corresponds to the comparison operator.", [
$this->logger->warning("Cannot evaluate condition ({$condition}) for setting '{$key}' ({$reason}). "
."Please check the User.{$attributeName} attribute and make sure that its value corresponds to the comparison operator.", [
'event_id' => 3004,
]);
}

private function logUserObjectAttributeIsAutoConverted(string $condition, string $key, string $attributeName, string $attributeValue): void
{
$this->logger->warning("Evaluation of condition ({$condition}) for setting '{$key}' may not produce the expected result ".
"(the User.{$attributeName} attribute is not a string value, thus it was automatically converted to the string value '{$attributeValue}'). ".
'Please make sure that using a non-string value was intended.', [
$this->logger->warning("Evaluation of condition ({$condition}) for setting '{$key}' may not produce the expected result "
."(the User.{$attributeName} attribute is not a string value, thus it was automatically converted to the string value '{$attributeValue}'). "
.'Please make sure that using a non-string value was intended.', [
'event_id' => 3005,
]);
}
Expand Down Expand Up @@ -1255,9 +1255,9 @@ private function checkDefaultValueTypeMismatch(mixed $returnValue, mixed $defaul
$settingTypeName = $settingType->name;
$defaultValueType = gettype($defaultValue);

$this->logger->warning("The type of a setting does not match the type of the specified default value ({$defaultValue}). ".
"Setting's type was {$settingTypeName} but the default value's type was {$defaultValueType}. ".
"Please make sure that using a default value not matching the setting's type was intended.", [
$this->logger->warning("The type of a setting does not match the type of the specified default value ({$defaultValue}). "
."Setting's type was {$settingTypeName} but the default value's type was {$defaultValueType}. "
."Please make sure that using a default value not matching the setting's type was intended.", [
'event_id' => 4002,
]);
}
Expand Down
36 changes: 18 additions & 18 deletions tests/ConfigCatClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ public function testConstructCacheRefreshIntervalOption()
$this->assertSame(20, $propInterval);
}

/**
* @dataProvider provideTestDataForSdkKeyFormat_ShouldBeValidated
*/
public function testSdkKeyFormatShouldBeValidated(string $sdkKey, bool $customBaseUrl, bool $isValid)
{
$clientOptions = $customBaseUrl
? [ClientOptions::BASE_URL => 'https://my-configcat-proxy']
: [];

if (!$isValid) {
$this->expectException(InvalidArgumentException::class);
} else {
$this->expectNotToPerformAssertions();
}

$client = new ConfigCatClient($sdkKey, $clientOptions);
}

public function provideTestDataForSdkKeyFormat_ShouldBeValidated()
{
return Utils::withDescription([
Expand All @@ -119,24 +137,6 @@ public function provideTestDataForSdkKeyFormat_ShouldBeValidated()
});
}

/**
* @dataProvider provideTestDataForSdkKeyFormat_ShouldBeValidated
*/
public function testSdkKeyFormatShouldBeValidated(string $sdkKey, bool $customBaseUrl, bool $isValid)
{
$clientOptions = $customBaseUrl
? [ClientOptions::BASE_URL => 'https://my-configcat-proxy']
: [];

if (!$isValid) {
$this->expectException(InvalidArgumentException::class);
} else {
$this->expectNotToPerformAssertions();
}

$client = new ConfigCatClient($sdkKey, $clientOptions);
}

public function testGetValueFailedFetch()
{
$client = new ConfigCatClient('testGetValueFailedFetc/h-34567890123456789012', [ClientOptions::FETCH_CLIENT => GuzzleFetchClient::create([
Expand Down
Loading

0 comments on commit 3d18ab2

Please sign in to comment.