Code improvements (#1649)

* use global namespace for faster lookups
* phpstan level 5
This commit is contained in:
Kevin Papst
2020-04-19 14:37:14 +02:00
committed by GitHub
parent 7b25e9acaf
commit 0f3fa8fdbe
183 changed files with 604 additions and 574 deletions

View File

@@ -95,7 +95,7 @@ class LdapDriver
$entries = $driver->searchEntries($filter, $baseDn, Ldap::SEARCH_SCOPE_SUB, $attributes);
// searchEntries don't return 'count' key as specified by php native function ldap_get_entries()
$entries['count'] = count($entries);
$entries['count'] = \count($entries);
} catch (LdapException $exception) {
$this->ldapExceptionHandler($exception);

View File

@@ -141,7 +141,7 @@ class LdapManager
}
$roleValue = $entries[0][$param];
if (is_array($roleValue)) {
if (\is_array($roleValue)) {
$roleValue = $roleValue[0];
}
$roles = $this->getRoles($roleValue, $roleParameter);
@@ -157,7 +157,7 @@ class LdapManager
return $this->driver->search(
$roleParameter['baseDn'],
sprintf('(&%s(%s=%s))', $filter, $roleParameter['userDnAttribute'], ldap_escape($dn, null, LDAP_ESCAPE_FILTER)),
sprintf('(&%s(%s=%s))', $filter, $roleParameter['userDnAttribute'], ldap_escape($dn, '', LDAP_ESCAPE_FILTER)),
[$roleParameter['nameAttribute']]
);
}

View File

@@ -66,7 +66,7 @@ class LdapUserHydrator
/** @var string|array|null $email */
$email = $user->getEmail();
if (is_array($email)) {
if (\is_array($email)) {
$user->setEmail($email[0]);
}
@@ -107,7 +107,7 @@ class LdapUserHydrator
$roleName = sprintf('ROLE_%s', self::slugify($roleName));
}
if (!in_array($roleName, $allowedRoles)) {
if (!\in_array($roleName, $allowedRoles)) {
continue;
}
@@ -130,17 +130,17 @@ class LdapUserHydrator
{
/** @var array $attr */
foreach ($attributeMap as $attr) {
if (!array_key_exists($attr['ldap_attr'], $ldapUserAttributes)) {
if (!\array_key_exists($attr['ldap_attr'], $ldapUserAttributes)) {
continue;
}
$ldapValue = $ldapUserAttributes[$attr['ldap_attr']];
if (array_key_exists('count', $ldapValue)) {
if (\array_key_exists('count', $ldapValue)) {
unset($ldapValue['count']);
}
if (1 === count($ldapValue)) {
if (1 === \count($ldapValue)) {
$value = array_shift($ldapValue);
} else {
$value = $ldapValue;

View File

@@ -69,8 +69,8 @@ class LdapUserProvider implements UserProviderInterface
public function refreshUser(UserInterface $user)
{
if (!($user instanceof User) || !$this->supportsClass(get_class($user))) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
if (!($user instanceof User) || !$this->supportsClass(\get_class($user))) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
}
if (!$user->isLdapUser() && null === $user->getPreferenceValue('ldap.dn')) {