10000 [Ldap] Add types to private properties by derrabus · Pull Request #42930 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Ldap] Add types to private properties #42930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand All @@ -40,23 +40,15 @@ 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);
}

/**
* {@inheritdoc}
*/
public function getEntryManager(): EntryManagerInterface
{
if (null === $this->entryManager) {
$this->entryManager = new EntryManager($this->getConnection());
}

return $this->entryManager;
return $this->entryManager ??= new EntryManager($this->getConnection());
}

/**
Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class EntryManager implements EntryManagerInterface
{
private $connection;
private Connection $connection;

public function __construct(Connection $connection)
{
Expand Down
28 changes: 10 additions & 18 deletions src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -51,7 +45,7 @@ public function __destruct()
$con = $this->connection->getResource();
$this->connection = null;

if (null === $this->results) {
if (!isset($this->results)) {
return;
}

Expand All @@ -63,15 +57,15 @@ public function __destruct()
throw new LdapException('Could not free results: '.ldap_error($con));
}
}
$this->results = null;
unset($this->results);
}

/**
* {@inheritdoc}
*/
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.');
Expand Down Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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 = [
[
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Ldap/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
*/
class Entry
{
private $dn;
private string $dn;

/**
* @var array<string, array>
*/
private $attributes = [];
private array $attributes = [];

/**
* @var array<string, string>
*/
private $lowerMap = [];
private array $lowerMap = [];

/**
* @param array<string, array> $attributes
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Ldap/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
final class Ldap implements LdapInterface
{
private $adapter;
private AdapterInterface $adapter;

public function __construct(AdapterInterface $adapter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class CheckLdapCredentialsListener implements EventSubscriberInterface
{
private $ldapLocator;
private ContainerInterface $ldapLocator;

public function __construct(ContainerInterface $ldapLocator)
{
Expand Down
13 changes: 6 additions & 7 deletions src/Symfony/Component/Ldap/Security/LdapAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 = '')
{
Expand Down
12 changes: 6 additions & 6 deletions src/Symfony/Component/Ldap/Security/LdapBadge.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/Ldap/Security/LdapUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
18 changes: 9 additions & 9 deletions src/Symfony/Component/Ldap/Security/LdapUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [])
{
Expand Down
0