Skip to content

Commit 000d449

Browse files
committed
Prefix all sprintf() calls
1 parent e9725ff commit 000d449

File tree

11 files changed

+30
-30
lines changed

11 files changed

+30
-30
lines changed

Adapter/AbstractConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function configureOptions(OptionsResolver $resolver): void
4242

4343
$resolver->setDefault('port', fn (Options $options) => 'ssl' === $options['encryption'] ? 636 : 389);
4444

45-
$resolver->setDefault('connection_string', fn (Options $options) => sprintf('ldap%s://%s:%s', 'ssl' === $options['encryption'] ? 's' : '', $options['host'], $options['port']));
45+
$resolver->setDefault('connection_string', fn (Options $options) => \sprintf('ldap%s://%s:%s', 'ssl' === $options['encryption'] ? 's' : '', $options['host'], $options['port']));
4646

4747
$resolver->setAllowedTypes('host', 'string');
4848
$resolver->setAllowedTypes('port', 'numeric');

Adapter/ExtLdap/Connection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ public function getResource(): ?LDAPConnection
9696
public function setOption(string $name, array|string|int|bool $value): void
9797
{
9898
if (!@ldap_set_option($this->connection, ConnectionOptions::getOption($name), $value)) {
99-
throw new LdapException(sprintf('Could not set value "%s" for option "%s".', $value, $name));
99+
throw new LdapException(\sprintf('Could not set value "%s" for option "%s".', $value, $name));
100100
}
101101
}
102102

103103
public function getOption(string $name): array|string|int|null
104104
{
105105
if (!@ldap_get_option($this->connection, ConnectionOptions::getOption($name), $ret)) {
106-
throw new LdapException(sprintf('Could not retrieve value for option "%s".', $name));
106+
throw new LdapException(\sprintf('Could not retrieve value for option "%s".', $name));
107107
}
108108

109109
return $ret;

Adapter/ExtLdap/ConnectionOptions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class ConnectionOptions
6565

6666
public static function getOptionName(string $name): string
6767
{
68-
return sprintf('%s::%s', self::class, strtoupper($name));
68+
return \sprintf('%s::%s', self::class, strtoupper($name));
6969
}
7070

7171
/**
@@ -80,7 +80,7 @@ public static function getOption(string $name): int
8080
$constantName = self::getOptionName($name);
8181

8282
if (!\defined($constantName)) {
83-
throw new LdapException(sprintf('Unknown option "%s".', $name));
83+
throw new LdapException(\sprintf('Unknown option "%s".', $name));
8484
}
8585

8686
return \constant($constantName);

Adapter/ExtLdap/EntryManager.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function add(Entry $entry): static
3737
$con = $this->getConnectionResource();
3838

3939
if (!@ldap_add($con, $entry->getDn(), $entry->getAttributes())) {
40-
throw new LdapException(sprintf('Could not add entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
40+
throw new LdapException(\sprintf('Could not add entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
4141
}
4242

4343
return $this;
@@ -51,7 +51,7 @@ public function update(Entry $entry): static
5151
$con = $this->getConnectionResource();
5252

5353
if (!@ldap_modify($con, $entry->getDn(), $entry->getAttributes())) {
54-
throw new LdapException(sprintf('Could not update entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
54+
throw new LdapException(\sprintf('Could not update entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
5555
}
5656

5757
return $this;
@@ -65,7 +65,7 @@ public function remove(Entry $entry): static
6565
$con = $this->getConnectionResource();
6666

6767
if (!@ldap_delete($con, $entry->getDn())) {
68-
throw new LdapException(sprintf('Could not remove entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
68+
throw new LdapException(\sprintf('Could not remove entry "%s": ', $entry->getDn()).ldap_error($con), ldap_errno($con));
6969
}
7070

7171
return $this;
@@ -84,7 +84,7 @@ public function addAttributeValues(Entry $entry, string $attribute, array $value
8484
$con = $this->getConnectionResource();
8585

8686
if (!@ldap_mod_add($con, $entry->getDn(), [$attribute => $values])) {
87-
throw new LdapException(sprintf('Could not add values to entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
87+
throw new LdapException(\sprintf('Could not add values to entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
8888
}
8989

9090
return $this;
@@ -103,7 +103,7 @@ public function removeAttributeValues(Entry $entry, string $attribute, array $va
103103
$con = $this->getConnectionResource();
104104

105105
if (!@ldap_mod_del($con, $entry->getDn(), [$attribute => $values])) {
106-
throw new LdapException(sprintf('Could not remove values from entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
106+
throw new LdapException(\sprintf('Could not remove values from entry "%s", attribute "%s": ', $entry->getDn(), $attribute).ldap_error($con), ldap_errno($con));
107107
}
108108

109109
return $this;
@@ -117,7 +117,7 @@ public function rename(Entry $entry, string $newRdn, bool $removeOldRdn = true):
117117
$con = $this->getConnectionResource();
118118

119119
if (!@ldap_rename($con, $entry->getDn(), $newRdn, '', $removeOldRdn)) {
120-
throw new LdapException(sprintf('Could not rename entry "%s" to "%s": ', $entry->getDn(), $newRdn).ldap_error($con), ldap_errno($con));
120+
throw new LdapException(\sprintf('Could not rename entry "%s" to "%s": ', $entry->getDn(), $newRdn).ldap_error($con), ldap_errno($con));
121121
}
122122

123123
return $this;
@@ -137,7 +137,7 @@ public function move(Entry $entry, string $newParent): static
137137
$con = $this->getConnectionResource();
138138
// deleteOldRdn does not matter here, since the Rdn will not be changing in the move.
139139
if (!@ldap_rename($con, $entry->getDn(), $rdn, $newParent, true)) {
140-
throw new LdapException(sprintf('Could not move entry "%s" to "%s": ', $entry->getDn(), $newParent).ldap_error($con), ldap_errno($con));
140+
throw new LdapException(\sprintf('Could not move entry "%s" to "%s": ', $entry->getDn(), $newParent).ldap_error($con), ldap_errno($con));
141141
}
142142

143143
return $this;
@@ -172,7 +172,7 @@ public function applyOperations(string $dn, iterable $operations): static
172172

173173
$con = $this->getConnectionResource();
174174
if (!@ldap_modify_batch($con, $dn, $operationsMapped)) {
175-
throw new UpdateOperationException(sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($con), ldap_errno($con));
175+
throw new UpdateOperationException(\sprintf('Error executing UpdateOperation on "%s": ', $dn).ldap_error($con), ldap_errno($con));
176176
}
177177

178178
return $this;
@@ -181,7 +181,7 @@ public function applyOperations(string $dn, iterable $operations): static
181181
private function parseRdnFromEntry(Entry $entry): string
182182
{
183183
if (!preg_match('/(^[^,\\\\]*(?:\\\\.[^,\\\\]*)*),/', $entry->getDn(), $matches)) {
184-
throw new LdapException(sprintf('Entry "%s" malformed, could not parse RDN.', $entry->getDn()));
184+
throw new LdapException(\sprintf('Entry "%s" malformed, could not parse RDN.', $entry->getDn()));
185185
}
186186

187187
return $matches[1];

Adapter/ExtLdap/Query.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function execute(): CollectionInterface
7373
static::SCOPE_BASE => 'ldap_read',
7474
static::SCOPE_ONE => 'ldap_list',
7575
static::SCOPE_SUB => 'ldap_search',
76-
default => throw new LdapException(sprintf('Could not search in scope "%s".', $this->options['scope'])),
76+
default => throw new LdapException(\sprintf('Could not search in scope "%s".', $this->options['scope'])),
7777
};
7878

7979
$itemsLeft = $maxItems = $this->options['maxItems'];
@@ -101,13 +101,13 @@ public function execute(): CollectionInterface
101101
if (false === $search) {
102102
$ldapError = '';
103103
if ($errno = ldap_errno($con)) {
104-
$ldapError = sprintf(' LDAP error was [%d] %s', $errno, ldap_error($con));
104+
$ldapError = \sprintf(' LDAP error was [%d] %s', $errno, ldap_error($con));
105105
}
106106
if ($pageControl) {
107107
$this->resetPagination();
108108
}
109109

110-
throw new LdapException(sprintf('Could not complete search with dn "%s", query "%s" and filters "%s".%s.', $this->dn, $this->query, implode(',', $this->options['filter']), $ldapError), $errno);
110+
throw new LdapException(\sprintf('Could not complete search with dn "%s", query "%s" and filters "%s".%s.', $this->dn, $this->query, implode(',', $this->options['filter']), $ldapError), $errno);
111111
}
112112

113113
$this->results[] = $search;

Adapter/ExtLdap/UpdateOperation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public function __construct(
3434
private ?array $values,
3535
) {
3636
if (!\in_array($operationType, self::VALID_OPERATION_TYPES, true)) {
37-
throw new UpdateOperationException(sprintf('"%s" is not a valid modification type.', $operationType));
37+
throw new UpdateOperationException(\sprintf('"%s" is not a valid modification type.', $operationType));
3838
}
3939
if (\LDAP_MODIFY_BATCH_REMOVE_ALL === $operationType && null !== $values) {
40-
throw new UpdateOperationException(sprintf('$values must be null for LDAP_MODIFY_BATCH_REMOVE_ALL operation, "%s" given.', get_debug_type($values)));
40+
throw new UpdateOperationException(\sprintf('$values must be null for LDAP_MODIFY_BATCH_REMOVE_ALL operation, "%s" given.', get_debug_type($values)));
4141
}
4242
}
4343

Ldap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function escape(string $subject, string $ignore = '', int $flags = 0): st
5656
public static function create(string $adapter, array $config = []): static
5757
{
5858
if ('ext_ldap' !== $adapter) {
59-
throw new DriverNotFoundException(sprintf('Adapter "%s" not found. Only "ext_ldap" is supported at the moment.', $adapter));
59+
throw new DriverNotFoundException(\sprintf('Adapter "%s" not found. Only "ext_ldap" is supported at the moment.', $adapter));
6060
}
6161

6262
return new self(new Adapter($config));

Security/CheckLdapCredentialsListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function onCheckPassport(CheckPassportEvent $event): void
4848
}
4949

5050
if (!$passport->hasBadge(PasswordCredentials::class)) {
51-
throw new \LogicException(sprintf('LDAP authentication requires a passport containing password credentials, authenticator "%s" does not fulfill these requirements.', $event->getAuthenticator()::class));
51+
throw new \LogicException(\sprintf('LDAP authentication requires a passport containing password credentials, authenticator "%s" does not fulfill these requirements.', $event->getAuthenticator()::class));
5252
}
5353

5454
/** @var PasswordCredentials $passwordCredentials */
@@ -58,7 +58,7 @@ public function onCheckPassport(CheckPassportEvent $event): void
5858
}
5959

6060
if (!$this->ldapLocator->has($ldapBadge->getLdapServiceId())) {
61-
throw new \LogicException(sprintf('Cannot check credentials using the "%s" ldap service, as such service is not found. Did you maybe forget to add the "ldap" service tag to this service?', $ldapBadge->getLdapServiceId()));
61+
throw new \LogicException(\sprintf('Cannot check credentials using the "%s" ldap service, as such service is not found. Did you maybe forget to add the "ldap" service tag to this service?', $ldapBadge->getLdapServiceId()));
6262
}
6363

6464
$presentedPassword = $passwordCredentials->getPassword();

Security/LdapAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
7575
public function start(Request $request, ?AuthenticationException $authException = null): Response
7676
{
7777
if (!$this->authenticator instanceof AuthenticationEntryPointInterface) {
78-
throw new NotAnEntryPointException(sprintf('Decorated authenticator "%s" does not implement interface "%s".', get_debug_type($this->authenticator), AuthenticationEntryPointInterface::class));
78+
throw new NotAnEntryPointException(\sprintf('Decorated authenticator "%s" does not implement interface "%s".', get_debug_type($this->authenticator), AuthenticationEntryPointInterface::class));
7979
}
8080

8181
return $this->authenticator->start($request, $authException);

Security/LdapUserProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface
7272
$count = \count($entries);
7373

7474
if (!$count) {
75-
$e = new UserNotFoundException(sprintf('User "%s" not found.', $identifier));
75+
$e = new UserNotFoundException(\sprintf('User "%s" not found.', $identifier));
7676
$e->setUserIdentifier($identifier);
7777

7878
throw $e;
@@ -98,7 +98,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface
9898
public function refreshUser(UserInterface $user): UserInterface
9999
{
100100
if (!$user instanceof LdapUser) {
101-
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
101+
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
102102
}
103103

104104
return new LdapUser($user->getEntry(), $user->getUserIdentifier(), $user->getPassword(), $user->getRoles(), $user->getExtraFields());
@@ -110,7 +110,7 @@ public function refreshUser(UserInterface $user): UserInterface
110110
public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
111111
{
112112
if (!$user instanceof LdapUser) {
113-
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
113+
throw new UnsupportedUserException(\sprintf('Instances of "%s" are not supported.', get_debug_type($user)));
114114
}
115115

116116
if (null === $this->passwordAttribute) {
@@ -153,7 +153,7 @@ protected function loadUser(string $identifier, Entry $entry): UserInterface
153153
private function getAttributeValue(Entry $entry, string $attribute): mixed
154154
{
155155
if (!$entry->hasAttribute($attribute)) {
156-
throw new InvalidArgumentException(sprintf('Missing attribute "%s" for user "%s".', $attribute, $entry->getDn()));
156+
throw new InvalidArgumentException(\sprintf('Missing attribute "%s" for user "%s".', $attribute, $entry->getDn()));
157157
}
158158

159159
$values = $entry->getAttribute($attribute);
@@ -162,7 +162,7 @@ private function getAttributeValue(Entry $entry, string $attribute): mixed
162162
}
163163

164164
if (1 !== \count($values)) {
165-
throw new InvalidArgumentException(sprintf('Attribute "%s" has multiple values.', $attribute));
165+
throw new InvalidArgumentException(\sprintf('Attribute "%s" has multiple values.', $attribute));
166166
}
167167

168168
return $values[0];

0 commit comments

Comments
 (0)