Skip to content

Commit c6c69bc

Browse files
committed
Prefix all sprintf() calls
1 parent cc0595e commit c6c69bc

27 files changed

+50
-50
lines changed

AccessToken/Cas/Cas2Handler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
) {
3434
if (null === $client) {
3535
if (!class_exists(HttpClient::class)) {
36-
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
36+
throw new \LogicException(\sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
3737
}
3838

3939
$this->client = HttpClient::create();
@@ -76,7 +76,7 @@ private function getValidationUrl(string $accessToken): string
7676
unset($query['ticket']);
7777
$queryString = $query ? '?'.http_build_query($query) : '';
7878

79-
return sprintf('%s?ticket=%s&service=%s',
79+
return \sprintf('%s?ticket=%s&service=%s',
8080
$this->validationUrl,
8181
urlencode($accessToken),
8282
urlencode($request->getSchemeAndHttpHost().$request->getBaseUrl().$request->getPathInfo().$queryString)

AccessToken/HeaderAccessTokenExtractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
private readonly string $headerParameter = 'Authorization',
2929
private readonly string $tokenType = 'Bearer',
3030
) {
31-
$this->regex = sprintf(
31+
$this->regex = \sprintf(
3232
'/^%s([a-zA-Z0-9\-_\+~\/\.]+=*)$/',
3333
'' === $this->tokenType ? '' : preg_quote($this->tokenType).'\s+'
3434
);

AccessToken/Oidc/OidcTokenHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getUserBadgeFrom(string $accessToken): UserBadge
9797
$claimCheckerManager->check($claims);
9898

9999
if (empty($claims[$this->claim])) {
100-
throw new MissingClaimException(sprintf('"%s" claim not found.', $this->claim));
100+
throw new MissingClaimException(\sprintf('"%s" claim not found.', $this->claim));
101101
}
102102

103103
// UserLoader argument can be overridden by a UserProvider on AccessTokenAuthenticator::authenticate

AccessToken/Oidc/OidcUserInfoTokenHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getUserBadgeFrom(string $accessToken): UserBadge
4343
])->toArray();
4444

4545
if (empty($claims[$this->claim])) {
46-
throw new MissingClaimException(sprintf('"%s" claim not found on OIDC server response.', $this->claim));
46+
throw new MissingClaimException(\sprintf('"%s" claim not found on OIDC server response.', $this->claim));
4747
}
4848

4949
// UserLoader argument can be overridden by a UserProvider on AccessTokenAuthenticator::authenticate

Authentication/AuthenticatorManager.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function supports(Request $request): ?bool
9696
$this->logger?->debug('Checking support on authenticator.', ['firewall_name' => $this->firewallName, 'authenticator' => $authenticator::class]);
9797

9898
if (!$authenticator instanceof AuthenticatorInterface) {
99-
throw new \InvalidArgumentException(sprintf('Authenticator "%s" must implement "%s".', get_debug_type($authenticator), AuthenticatorInterface::class));
99+
throw new \InvalidArgumentException(\sprintf('Authenticator "%s" must implement "%s".', get_debug_type($authenticator), AuthenticatorInterface::class));
100100
}
101101

102102
if (false !== $supports = $authenticator->supports($request)) {
@@ -174,15 +174,15 @@ private function executeAuthenticator(AuthenticatorInterface $authenticator, Req
174174
$resolvedBadges = [];
175175
foreach ($passport->getBadges() as $badge) {
176176
if (!$badge->isResolved()) {
177-
throw new BadCredentialsException(sprintf('Authentication failed: Security badge "%s" is not resolved, did you forget to register the correct listeners?', get_debug_type($badge)));
177+
throw new BadCredentialsException(\sprintf('Authentication failed: Security badge "%s" is not resolved, did you forget to register the correct listeners?', get_debug_type($badge)));
178178
}
179179

180180
$resolvedBadges[] = $badge::class;
181181
}
182182

183183
$missingRequiredBadges = array_diff($this->requiredBadges, $resolvedBadges);
184184
if ($missingRequiredBadges) {
185-
throw new BadCredentialsException(sprintf('Authentication failed; Some badges marked as required by the firewall config are not available on the passport: "%s".', implode('", "', $missingRequiredBadges)));
185+
throw new BadCredentialsException(\sprintf('Authentication failed; Some badges marked as required by the firewall config are not available on the passport: "%s".', implode('", "', $missingRequiredBadges)));
186186
}
187187

188188
// create the authentication token

Authentication/DefaultAuthenticationFailureHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7070
if (\is_string($failureUrl) && (str_starts_with($failureUrl, '/') || str_starts_with($failureUrl, 'http'))) {
7171
$options['failure_path'] = $failureUrl;
7272
} elseif ($this->logger && $failureUrl) {
73-
$this->logger->debug(sprintf('Ignoring query parameter "%s": not a valid URL.', $options['failure_path_parameter']));
73+
$this->logger->debug(\sprintf('Ignoring query parameter "%s": not a valid URL.', $options['failure_path_parameter']));
7474
}
7575

7676
$options['failure_path'] ??= $options['login_path'];

Authentication/DefaultAuthenticationSuccessHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function determineTargetUrl(Request $request): string
9595
}
9696

9797
if ($this->logger && $targetUrl) {
98-
$this->logger->debug(sprintf('Ignoring query parameter "%s": not a valid URL.', $this->options['target_path_parameter']));
98+
$this->logger->debug(\sprintf('Ignoring query parameter "%s": not a valid URL.', $this->options['target_path_parameter']));
9999
}
100100

101101
$firewallName = $this->getFirewallName();

Authenticator/AccessTokenAuthenticator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private function getAuthenticateHeader(?string $errorDescription = null): string
115115
if (null === $v || '' === $v) {
116116
continue;
117117
}
118-
$values[] = sprintf('%s="%s"', $k, $v);
118+
$values[] = \sprintf('%s="%s"', $k, $v);
119119
}
120120

121-
return sprintf('Bearer %s', implode(',', $values));
121+
return \sprintf('Bearer %s', implode(',', $values));
122122
}
123123
}

Authenticator/FormLoginAuthenticator.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,27 @@ private function getCredentials(Request $request): array
122122
}
123123

124124
if (!\is_string($credentials['username']) && !$credentials['username'] instanceof \Stringable) {
125-
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['username_parameter'], \gettype($credentials['username'])));
125+
throw new BadRequestHttpException(\sprintf('The key "%s" must be a string, "%s" given.', $this->options['username_parameter'], \gettype($credentials['username'])));
126126
}
127127

128128
$credentials['username'] = trim($credentials['username']);
129129

130130
if ('' === $credentials['username']) {
131-
throw new BadCredentialsException(sprintf('The key "%s" must be a non-empty string.', $this->options['username_parameter']));
131+
throw new BadCredentialsException(\sprintf('The key "%s" must be a non-empty string.', $this->options['username_parameter']));
132132
}
133133

134134
$request->getSession()->set(SecurityRequestAttributes::LAST_USERNAME, $credentials['username']);
135135

136136
if (!\is_string($credentials['password']) && (!\is_object($credentials['password']) || !method_exists($credentials['password'], '__toString'))) {
137-
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['password_parameter'], \gettype($credentials['password'])));
137+
throw new BadRequestHttpException(\sprintf('The key "%s" must be a string, "%s" given.', $this->options['password_parameter'], \gettype($credentials['password'])));
138138
}
139139

140140
if ('' === (string) $credentials['password']) {
141-
throw new BadCredentialsException(sprintf('The key "%s" must be a non-empty string.', $this->options['password_parameter']));
141+
throw new BadCredentialsException(\sprintf('The key "%s" must be a non-empty string.', $this->options['password_parameter']));
142142
}
143143

144144
if (!\is_string($credentials['csrf_token'] ?? '') && (!\is_object($credentials['csrf_token']) || !method_exists($credentials['csrf_token'], '__toString'))) {
145-
throw new BadRequestHttpException(sprintf('The key "%s" must be a string, "%s" given.', $this->options['csrf_parameter'], \gettype($credentials['csrf_token'])));
145+
throw new BadRequestHttpException(\sprintf('The key "%s" must be a string, "%s" given.', $this->options['csrf_parameter'], \gettype($credentials['csrf_token'])));
146146
}
147147

148148
return $credentials;

Authenticator/HttpBasicAuthenticator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
public function start(Request $request, ?AuthenticationException $authException = null): Response
4444
{
4545
$response = new Response();
46-
$response->headers->set('WWW-Authenticate', sprintf('Basic realm="%s"', $this->realmName));
46+
$response->headers->set('WWW-Authenticate', \sprintf('Basic realm="%s"', $this->realmName));
4747
$response->setStatusCode(401);
4848

4949
return $response;

Authenticator/JsonLoginAuthenticator.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,21 @@ private function getCredentials(\stdClass $data): array
147147
$credentials['username'] = $this->propertyAccessor->getValue($data, $this->options['username_path']);
148148

149149
if (!\is_string($credentials['username']) || '' === $credentials['username']) {
150-
throw new BadRequestHttpException(sprintf('The key "%s" must be a non-empty string.', $this->options['username_path']));
150+
throw new BadRequestHttpException(\sprintf('The key "%s" must be a non-empty string.', $this->options['username_path']));
151151
}
152152
} catch (AccessException $e) {
153-
throw new BadRequestHttpException(sprintf('The key "%s" must be provided.', $this->options['username_path']), $e);
153+
throw new BadRequestHttpException(\sprintf('The key "%s" must be provided.', $this->options['username_path']), $e);
154154
}
155155

156156
try {
157157
$credentials['password'] = $this->propertyAccessor->getValue($data, $this->options['password_path']);
158158
$this->propertyAccessor->setValue($data, $this->options['password_path'], null);
159159

160160
if (!\is_string($credentials['password']) || '' === $credentials['password']) {
161-
throw new BadRequestHttpException(sprintf('The key "%s" must be a non-empty string.', $this->options['password_path']));
161+
throw new BadRequestHttpException(\sprintf('The key "%s" must be a non-empty string.', $this->options['password_path']));
162162
}
163163
} catch (AccessException $e) {
164-
throw new BadRequestHttpException(sprintf('The key "%s" must be provided.', $this->options['password_path']), $e);
164+
throw new BadRequestHttpException(\sprintf('The key "%s" must be provided.', $this->options['password_path']), $e);
165165
}
166166

167167
return $credentials;

Authenticator/Passport/Badge/UserBadge.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function getUser(): UserInterface
7979
}
8080

8181
if (null === $this->userLoader) {
82-
throw new \LogicException(sprintf('No user loader is configured, did you forget to register the "%s" listener?', UserProviderListener::class));
82+
throw new \LogicException(\sprintf('No user loader is configured, did you forget to register the "%s" listener?', UserProviderListener::class));
8383
}
8484

8585
if (null === $this->getAttributes()) {
@@ -97,7 +97,7 @@ public function getUser(): UserInterface
9797
}
9898

9999
if (!$user instanceof UserInterface) {
100-
throw new AuthenticationServiceException(sprintf('The user provider must return a UserInterface object, "%s" given.', get_debug_type($user)));
100+
throw new AuthenticationServiceException(\sprintf('The user provider must return a UserInterface object, "%s" given.', get_debug_type($user)));
101101
}
102102

103103
return $this->user = $user;

Authenticator/RemoteUserAuthenticator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
protected function extractUsername(Request $request): ?string
4242
{
4343
if (!$request->server->has($this->userKey)) {
44-
throw new BadCredentialsException(sprintf('User key was not found: "%s".', $this->userKey));
44+
throw new BadCredentialsException(\sprintf('User key was not found: "%s".', $this->userKey));
4545
}
4646

4747
return $request->server->get($this->userKey);

Authenticator/X509Authenticator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function extractUsername(Request $request): string
5353
}
5454

5555
if (null === $username) {
56-
throw new BadCredentialsException(sprintf('SSL credentials not found: "%s", "%s".', $this->userKey, $this->credentialsKey));
56+
throw new BadCredentialsException(\sprintf('SSL credentials not found: "%s", "%s".', $this->userKey, $this->credentialsKey));
5757
}
5858

5959
return $username;

Controller/UserValueResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
4747
}
4848

4949
if (!$argument->isNullable()) {
50-
throw new AccessDeniedException(sprintf('There is no logged-in user to pass to $%s, make the argument nullable if you want to allow anonymous access to the action.', $argument->getName()));
50+
throw new AccessDeniedException(\sprintf('There is no logged-in user to pass to $%s, make the argument nullable if you want to allow anonymous access to the action.', $argument->getName()));
5151
}
5252

5353
return [null];
@@ -57,6 +57,6 @@ public function resolve(Request $request, ArgumentMetadata $argument): array
5757
return [$user];
5858
}
5959

60-
throw new AccessDeniedException(sprintf('The logged-in user is an instance of "%s" but a user of type "%s" is expected.', $user::class, $argument->getType()));
60+
throw new AccessDeniedException(\sprintf('The logged-in user is an instance of "%s" but a user of type "%s" is expected.', $user::class, $argument->getType()));
6161
}
6262
}

EventListener/CheckCredentialsListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function checkPassport(CheckPassportEvent $event): void
4444
$user = $passport->getUser();
4545

4646
if (!$user instanceof PasswordAuthenticatedUserInterface) {
47-
throw new \LogicException(sprintf('Class "%s" must implement "%s" for using password-based authentication.', get_debug_type($user), PasswordAuthenticatedUserInterface::class));
47+
throw new \LogicException(\sprintf('Class "%s" must implement "%s" for using password-based authentication.', get_debug_type($user), PasswordAuthenticatedUserInterface::class));
4848
}
4949

5050
/** @var PasswordCredentials $badge */

EventListener/IsGrantedAttributeListener.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
6060
}
6161

6262
if (!$this->authChecker->isGranted($attribute->attribute, $subject)) {
63-
$message = $attribute->message ?: sprintf('Access Denied by #[IsGranted(%s)] on controller', $this->getIsGrantedString($attribute));
63+
$message = $attribute->message ?: \sprintf('Access Denied by #[IsGranted(%s)] on controller', $this->getIsGrantedString($attribute));
6464

6565
if ($statusCode = $attribute->statusCode) {
6666
throw new HttpException($statusCode, $message, code: $attribute->exceptionCode ?? 0);
@@ -92,23 +92,23 @@ private function getIsGrantedSubject(string|Expression $subjectRef, Request $req
9292
}
9393

9494
if (!\array_key_exists($subjectRef, $arguments)) {
95-
throw new RuntimeException(sprintf('Could not find the subject "%s" for the #[IsGranted] attribute. Try adding a "$%s" argument to your controller method.', $subjectRef, $subjectRef));
95+
throw new RuntimeException(\sprintf('Could not find the subject "%s" for the #[IsGranted] attribute. Try adding a "$%s" argument to your controller method.', $subjectRef, $subjectRef));
9696
}
9797

9898
return $arguments[$subjectRef];
9999
}
100100

101101
private function getIsGrantedString(IsGranted $isGranted): string
102102
{
103-
$processValue = fn ($value) => sprintf($value instanceof Expression ? 'new Expression("%s")' : '"%s"', $value);
103+
$processValue = fn ($value) => \sprintf($value instanceof Expression ? 'new Expression("%s")' : '"%s"', $value);
104104

105105
$argsString = $processValue($isGranted->attribute);
106106

107107
if (null !== $subject = $isGranted->subject) {
108108
$subject = !\is_array($subject) ? $processValue($subject) : array_map(function ($key, $value) use ($processValue) {
109109
$value = $processValue($value);
110110

111-
return \is_string($key) ? sprintf('"%s" => %s', $key, $value) : $value;
111+
return \is_string($key) ? \sprintf('"%s" => %s', $key, $value) : $value;
112112
}, array_keys($subject), $subject);
113113

114114
$argsString .= ', '.(!\is_array($subject) ? $subject : '['.implode(', ', $subject).']');

Firewall/AccessListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(
3737
bool $exceptionOnNoToken = false,
3838
) {
3939
if (false !== $exceptionOnNoToken) {
40-
throw new \LogicException(sprintf('Argument $exceptionOnNoToken of "%s()" must be set to "false".', __METHOD__));
40+
throw new \LogicException(\sprintf('Argument $exceptionOnNoToken of "%s()" must be set to "false".', __METHOD__));
4141
}
4242
}
4343

Firewall/ContextListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ protected function refreshUser(TokenInterface $token): ?TokenInterface
194194

195195
foreach ($this->userProviders as $provider) {
196196
if (!$provider instanceof UserProviderInterface) {
197-
throw new \InvalidArgumentException(sprintf('User provider "%s" must implement "%s".', get_debug_type($provider), UserProviderInterface::class));
197+
throw new \InvalidArgumentException(\sprintf('User provider "%s" must implement "%s".', get_debug_type($provider), UserProviderInterface::class));
198198
}
199199

200200
if (!$provider->supportsClass($userClass)) {
@@ -246,7 +246,7 @@ protected function refreshUser(TokenInterface $token): ?TokenInterface
246246
return null;
247247
}
248248

249-
throw new \RuntimeException(sprintf('There is no user provider for user "%s". Shouldn\'t the "supportsClass()" method of your user provider return true for this classname?', $userClass));
249+
throw new \RuntimeException(\sprintf('There is no user provider for user "%s". Shouldn\'t the "supportsClass()" method of your user provider return true for this classname?', $userClass));
250250
}
251251

252252
private function safelyUnserialize(string $serializedToken): mixed

Firewall/ExceptionListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private function startAuthentication(Request $request, AuthenticationException $
201201
if (!$response instanceof Response) {
202202
$given = get_debug_type($response);
203203

204-
throw new \LogicException(sprintf('The "%s::start()" method must return a Response object ("%s" returned).', get_debug_type($this->authenticationEntryPoint), $given));
204+
throw new \LogicException(\sprintf('The "%s::start()" method must return a Response object ("%s" returned).', get_debug_type($this->authenticationEntryPoint), $given));
205205
}
206206

207207
return $response;
@@ -217,7 +217,7 @@ protected function setTargetPath(Request $request): void
217217

218218
private function throwUnauthorizedException(AuthenticationException $authException): never
219219
{
220-
$this->logger?->notice(sprintf('No Authentication entry point configured, returning a %s HTTP response. Configure "entry_point" on the firewall "%s" if you want to modify the response.', Response::HTTP_UNAUTHORIZED, $this->firewallName));
220+
$this->logger?->notice(\sprintf('No Authentication entry point configured, returning a %s HTTP response. Configure "entry_point" on the firewall "%s" if you want to modify the response.', Response::HTTP_UNAUTHORIZED, $this->firewallName));
221221

222222
throw new HttpException(Response::HTTP_UNAUTHORIZED, $authException->getMessage(), $authException, [], $authException->getCode());
223223
}

0 commit comments

Comments
 (0)