diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php index 7b7875ef806c7..eb2ee9daab7bb 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php @@ -22,9 +22,9 @@ */ class Adapter implements AdapterInterface { - private $config; - private $connection; - private $entryManager; + private array $config; + private ConnectionInterface $connection; + private EntryManagerInterface $entryManager; public function __construct(array $config = []) { @@ -40,11 +40,7 @@ public function __construct(array $config = []) */ public function getConnection(): ConnectionInterface { - if (null === $this->connection) { - $this->connection = new Connection($this->config); - } - - return $this->connection; + return $this->connection ??= new Connection($this->config); } /** @@ -52,11 +48,7 @@ public function getConnection(): ConnectionInterface */ public function getEntryManager(): EntryManagerInterface { - if (null === $this->entryManager) { - $this->entryManager = new EntryManager($this->getConnection()); - } - - return $this->entryManager; + return $this->entryManager ??= new EntryManager($this->getConnection()); } /** diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php index 123d7f8516416..5feb7c0ec1049 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php @@ -20,9 +20,9 @@ */ class Collection implements CollectionInterface { - private $connection; - private $search; - private $entries; + private Connection $connection; + private Query $search; + private array $entries; public function __construct(Connection $connection, Query $search) { @@ -35,11 +35,7 @@ public function __construct(Connection $connection, Query $search) */ public function toArray(): array { - if (null === $this->entries) { - $this->entries = iterator_to_array($this->getIterator(), false); - } - - return $this->entries; + return $this->entries ??= iterator_to_array($this->getIterator(), false); } public function count(): int diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php index cbcaf3efb43e4..ff898f1ec876a 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php @@ -29,8 +29,7 @@ class Connection extends AbstractConnection private const LDAP_TIMEOUT = 0x55; private const LDAP_ALREADY_EXISTS = 0x44; - /** @var bool */ - private $bound = false; + private bool $bound = false; /** @var resource */ private $connection; diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php index 6f0bdd4f61b74..2191e407e8107 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php @@ -23,7 +23,7 @@ */ class EntryManager implements EntryManagerInterface { - private $connection; + private Connection $connection; public function __construct(Connection $connection) { diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php index 5e8563e21acfa..f6d51a81e808c 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php @@ -26,15 +26,9 @@ class Query extends AbstractQuery public const PAGINATION_OID = '1.2.840.113556.1.4.319'; /** @var resource[] */ - private $results; + private array $results; - /** @var array */ - private $serverctrls = []; - - public function __construct(Connection $connection, string $dn, string $query, array $options = []) - { - parent::__construct($connection, $dn, $query, $options); - } + private array $serverctrls = []; public function __sleep(): array { @@ -51,7 +45,7 @@ public function __destruct() $con = $this->connection->getResource(); $this->connection = null; - if (null === $this->results) { + if (!isset($this->results)) { return; } @@ -63,7 +57,7 @@ public function __destruct() throw new LdapException('Could not free results: '.ldap_error($con)); } } - $this->results = null; + unset($this->results); } /** @@ -71,7 +65,7 @@ public function __destruct() */ public function execute(): CollectionInterface { - if (null === $this->results) { + if (!isset($this->results)) { // If the connection is not bound, throw an exception. Users should use an explicit bind call first. if (!$this->connection->isBound()) { throw new NotBoundException('Query execution is not possible without binding the connection first.'); @@ -108,7 +102,7 @@ public function execute(): CollectionInterface $cookie = ''; do { if ($pageControl) { - $this->controlPagedResult($con, $pageSize, true, $cookie); + $this->controlPagedResult($pageSize, true, $cookie); } $sizeLimit = $itemsLeft; if ($pageSize > 0 && $sizeLimit >= $pageSize) { @@ -135,7 +129,7 @@ public function execute(): CollectionInterface break; } if ($pageControl) { - $cookie = $this->controlPagedResultResponse($con, $search, $cookie); + $cookie = $this->controlPagedResultResponse($con, $search); } } while (null !== $cookie && '' !== $cookie); @@ -178,7 +172,7 @@ public function getResources(): array private function resetPagination() { $con = $this->connection->getResource(); - $this->controlPagedResult($con, 0, false, ''); + $this->controlPagedResult(0, false, ''); $this->serverctrls = []; // This is a workaround for a bit of a bug in the above invocation @@ -205,10 +199,8 @@ private function resetPagination() /** * Sets LDAP pagination controls. - * - * @param resource $con */ - private function controlPagedResult($con, int $pageSize, bool $critical, string $cookie): bool + private function controlPagedResult(int $pageSize, bool $critical, string $cookie): bool { $this->serverctrls = [ [ @@ -230,7 +222,7 @@ private function controlPagedResult($con, int $pageSize, bool $critical, string * @param resource $con * @param resource $result */ - private function controlPagedResultResponse($con, $result, string $cookie = ''): string + private function controlPagedResultResponse($con, $result): string { ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls); diff --git a/src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php b/src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php index cb57c1d6296ea..c2be3d57d48fb 100644 --- a/src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php +++ b/src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php @@ -15,9 +15,9 @@ class UpdateOperation { - private $operationType; - private $values; - private $attribute; + private int $operationType; + private ?array $values; + private string $attribute; private const VALID_OPERATION_TYPES = [ \LDAP_MODIFY_BATCH_ADD, diff --git a/src/Symfony/Component/Ldap/Entry.php b/src/Symfony/Component/Ldap/Entry.php index af438d182d52e..b1a60635ba172 100644 --- a/src/Symfony/Component/Ldap/Entry.php +++ b/src/Symfony/Component/Ldap/Entry.php @@ -17,17 +17,17 @@ */ class Entry { - private $dn; + private string $dn; /** * @var array */ - private $attributes = []; + private array $attributes = []; /** * @var array */ - private $lowerMap = []; + private array $lowerMap = []; /** * @param array $attributes diff --git a/src/Symfony/Component/Ldap/Ldap.php b/src/Symfony/Component/Ldap/Ldap.php index e3c6ace140f29..9c717ce11bacb 100644 --- a/src/Symfony/Component/Ldap/Ldap.php +++ b/src/Symfony/Component/Ldap/Ldap.php @@ -22,7 +22,7 @@ */ final class Ldap implements LdapInterface { - private $adapter; + private AdapterInterface $adapter; public function __construct(AdapterInterface $adapter) { diff --git a/src/Symfony/Component/Ldap/Security/CheckLdapCredentialsListener.php b/src/Symfony/Component/Ldap/Security/CheckLdapCredentialsListener.php index 99b965c4d05c0..1980e7726a493 100644 --- a/src/Symfony/Component/Ldap/Security/CheckLdapCredentialsListener.php +++ b/src/Symfony/Component/Ldap/Security/CheckLdapCredentialsListener.php @@ -28,7 +28,7 @@ */ class CheckLdapCredentialsListener implements EventSubscriberInterface { - private $ldapLocator; + private ContainerInterface $ldapLocator; public function __construct(ContainerInterface $ldapLocator) { diff --git a/src/Symfony/Component/Ldap/Security/LdapAuthenticator.php b/src/Symfony/Component/Ldap/Security/LdapAuthenticator.php index 4211d792b2574..00802a5004207 100644 --- a/src/Symfony/Component/Ldap/Security/LdapAuthenticator.php +++ b/src/Symfony/Component/Ldap/Security/LdapAuthenticator.php @@ -17,7 +17,6 @@ use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\Passport\Passport; -use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; /** * This class decorates internal authenticators to add the LDAP integration. @@ -32,12 +31,12 @@ */ class LdapAuthenticator implements AuthenticatorInterface { - private $authenticator; - private $ldapServiceId; - private $dnString; - private $searchDn; - private $searchPassword; - private $queryString; + private AuthenticatorInterface $authenticator; + private string $ldapServiceId; + private string $dnString; + private string $searchDn; + private string $searchPassword; + private string $queryString; public function __construct(AuthenticatorInterface $authenticator, string $ldapServiceId, string $dnString = '{username}', string $searchDn = '', string $searchPassword = '', string $queryString = '') { diff --git a/src/Symfony/Component/Ldap/Security/LdapBadge.php b/src/Symfony/Component/Ldap/Security/LdapBadge.php index af18e9817819e..4f78a39f9d0ba 100644 --- a/src/Symfony/Component/Ldap/Security/LdapBadge.php +++ b/src/Symfony/Component/Ldap/Security/LdapBadge.php @@ -24,12 +24,12 @@ */ class LdapBadge implements BadgeInterface { - private $resolved = false; - private $ldapServiceId; - private $dnString; - private $searchDn; - private $searchPassword; - private $queryString; + private bool $resolved = false; + private string $ldapServiceId; + private string $dnString; + private string $searchDn; + private string $searchPassword; + private ?string $queryString; public function __construct(string $ldapServiceId, string $dnString = '{username}', string $searchDn = '', string $searchPassword = '', string $queryString = null) { diff --git a/src/Symfony/Component/Ldap/Security/LdapUser.php b/src/Symfony/Component/Ldap/Security/LdapUser.php index b29429bb023ba..c5f4e6a7f8901 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUser.php +++ b/src/Symfony/Component/Ldap/Security/LdapUser.php @@ -23,11 +23,11 @@ */ class LdapUser implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface { - private $entry; - private $username; - private $password; - private $roles; - private $extraFields; + private Entry $entry; + private string $username; + private ?string $password; + private array $roles; + private array $extraFields; public function __construct(Entry $entry, string $username, ?string $password, array $roles = [], array $extraFields = []) { diff --git a/src/Symfony/Component/Ldap/Security/LdapUserProvider.php b/src/Symfony/Component/Ldap/Security/LdapUserProvider.php index 022c11b5ea664..01e4505199cdc 100644 --- a/src/Symfony/Component/Ldap/Security/LdapUserProvider.php +++ b/src/Symfony/Component/Ldap/Security/LdapUserProvider.php @@ -32,15 +32,15 @@ */ class LdapUserProvider implements UserProviderInterface, PasswordUpgraderInterface { - private $ldap; - private $baseDn; - private $searchDn; - private $searchPassword; - private $defaultRoles; - private $uidKey; - private $defaultSearch; - private $passwordAttribute; - private $extraFields; + private LdapInterface $ldap; + private string $baseDn; + private ?string $searchDn; + private ?string $searchPassword; + private array $defaultRoles; + private ?string $uidKey; + private string $defaultSearch; + private ?string $passwordAttribute; + private array $extraFields; public function __construct(LdapInterface $ldap, string $baseDn, string $searchDn = null, string $searchPassword = null, array $defaultRoles = [], string $uidKey = null, string $filter = null, string $passwordAttribute = null, array $extraFields = []) {