10000 minor #42930 [Ldap] Add types to private properties (derrabus) · symfony/symfony@3aa3b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3aa3b9d

Browse files
minor #42930 [Ldap] Add types to private properties (derrabus)
This PR was merged into the 6.0 branch. Discussion ---------- [Ldap] Add types to private properties | Q | A | ------------- | --- | Branch? | 6.0 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | N/A | License | MIT | Doc PR | N/A Commits ------- 03b97c8 [Ldap] Add types to private properties
2 parents b2a1d8c + 03b97c8 commit 3aa3b9d

File tree

13 files changed

+55
-77
lines changed

13 files changed

+55
-77
lines changed

src/Symfony/Component/Ldap/Adapter/ExtLdap/Adapter.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
*/
2323
class Adapter implements AdapterInterface
2424
{
25-
private $config;
26-
private $connection;
27-
private $entryManager;
25+
private array $config;
26+
private ConnectionInterface $connection;
27+
private EntryManagerInterface $entryManager;
2828

2929
public function __construct(array $config = [])
3030
{
@@ -40,23 +40,15 @@ public function __construct(array $config = [])
4040
*/
4141
public function getConnection(): ConnectionInterface
4242
{
43-
if (null === $this->connection) {
44-
$this->connection = new Connection($this->config);
45-
}
46-
47-
return $this->connection;
43+
return $this->connection ??= new Connection($this->config);
4844
}
4945

5046
/**
5147
* {@inheritdoc}
5248
*/
5349
public function getEntryManager(): EntryManagerInterface
5450
{
55-
if (null === $this->entryManager) {
56-
$this->entryManager = 6D4E new EntryManager($this->getConnection());
57-
}
58-
59-
return $this->entryManager;
51+
return $this->entryManager ??= new EntryManager($this->getConnection());
6052
}
6153

6254
/**

src/Symfony/Component/Ldap/Adapter/ExtLdap/Collection.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
class Collection implements CollectionInterface
2222
{
23-
private $connection;
24-
private $search;
25-
private $entries;
23+
private Connection $connection;
24+
private Query $search;
25+
private array $entries;
2626

2727
public function __construct(Connection $connection, Query $search)
2828
{
@@ -35,11 +35,7 @@ public function __construct(Connection $connection, Query $search)
3535
*/
3636
public function toArray(): array
3737
{
38-
if (null === $this->entries) {
39-
$this->entries = iterator_to_array($this->getIterator(), false);
40-
}
41-
42-
return $this->entries;
38+
return $this->entries ??= iterator_to_array($this->getIterator(), false);
4339
}
4440

4541
public function count(): int

src/Symfony/Component/Ldap/Adapter/ExtLdap/Connection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class Connection extends AbstractConnection
2929
private const LDAP_TIMEOUT = 0x55;
3030
private const LDAP_ALREADY_EXISTS = 0x44;
3131

32-
/** @var bool */
33-
private $bound = false;
32+
private bool $bound = false;
3433

3534
/** @var resource */
3635
private $connection;

src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424
class EntryManager implements EntryManagerInterface
2525
{
26-
private $connection;
26+
private Connection $connection;
2727

2828
public function __construct(Connection $connection)
2929
{

src/Symfony/Component/Ldap/Adapter/ExtLdap/Query.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,9 @@ class Query extends AbstractQuery
2626
public const PAGINATION_OID = '1.2.840.113556.1.4.319';
2727

2828
/** @var resource[] */
29-
private $results;
29+
private array $results;
3030

31-
/** @var array */
32-
private $serverctrls = [];
33-
34-
public function __construct(Connection $connection, string $dn, string $query, array $options = [])
35-
{
36-
parent::__construct($connection, $dn, $query, $options);
37-
}
31+
private array $serverctrls = [];
3832

3933
public function __sleep(): array
4034
{
@@ -51,7 +45,7 @@ public function __destruct()
5145
$con = $this->connection->getResource();
5246
$this->connection = null;
5347

54-
if (null === $this->results) {
48+
if (!isset($this->results)) {
5549
return;
5650
}
5751

@@ -63,15 +57,15 @@ public function __destruct()
6357
throw new LdapException('Could not free results: '.ldap_error($con));
6458
}
6559
}
66-
$this->results = null;
60+
unset($this->results);
6761
}
6862

6963
/**
7064
* {@inheritdoc}
7165
*/
7266
public function execute(): CollectionInterface
7367
{
74-
if (null === $this->results) {
68+
if (!isset($this->results)) {
7569
// If the connection is not bound, throw an exception. Users should use an explicit bind call first.
7670
if (!$this->connection->isBound()) {
7771
throw new NotBoundException('Query execution is not possible without binding the connection first.');
@@ -108,7 +102,7 @@ public function execute(): CollectionInterface
108102
$cookie = '';
109103
do {
110104
if ($pageControl) {
111-
$this->controlPagedResult($con, $pageSize, true, $cookie);
105+
$this->controlPagedResult($pageSize, true, $cookie);
112106
}
113107
$sizeLimit = $itemsLeft;
114108
if ($pageSize > 0 && $sizeLimit >= $pageSize) {
@@ -135,7 +129,7 @@ public function execute(): CollectionInterface
135129
break;
136130
}
137131
if ($pageControl) {
138-
$cookie = $this->controlPagedResultResponse($con, $search, $cookie);
132+
$cookie = $this->controlPagedResultResponse($con, $search);
139133
}
140134
} while (null !== $cookie && '' !== $cookie);
141135

@@ -178,7 +172,7 @@ public function getResources(): array
178172
private function resetPagination()
179173
{
180174
$con = $this->connection->getResource();
181-
$this->controlPagedResult($con, 0, false, '');
175+
$this->controlPagedResult(0, false, '');
182176
$this->serverctrls = [];
183177

184178
// This is a workaround for a bit of a bug in the above invocation
@@ -205,10 +199,8 @@ private function resetPagination()
205199

206200
/**
207201
* Sets LDAP pagination controls.
208-
*
209-
* @param resource $con
210202
*/
211-
private function controlPagedResult($con, int $pageSize, bool $critical, string $cookie): bool
203+
private function controlPagedResult(int $pageSize, bool $critical, string $cookie): bool
212204
{
213205
$this->serverctrls = [
214206
[
@@ -230,7 +222,7 @@ private function controlPagedResult($con, int $pageSize, bool $critical, string
230222
* @param resource $con
231223
* @param resource $result
232224
*/
233-
private function controlPagedResultResponse($con, $result, string $cookie = ''): string
225+
private function controlPagedResultResponse($con, $result): string
234226
{
235227
ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls);
236228

src/Symfony/Component/Ldap/Adapter/ExtLdap/UpdateOperation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
class UpdateOperation
1717
{
18-
private $operationType;
19-
private $values;
20-
private $attribute;
18+
private int $operationType;
19+
private ?array $values;
20+
private string $attribute;
2121

2222
private const VALID_OPERATION_TYPES = [
2323
\LDAP_MODIFY_BATCH_ADD,

src/Symfony/Component/Ldap/Entry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
*/
1818
class Entry
1919
{
20-
private $dn;
20+
private string $dn;
2121

2222
/**
2323
* @var array<string, array>
2424
*/
25-
private $attributes = [];
25+
private array $attributes = [];
2626

2727
/**
2828
* @var array<string, string>
2929
*/
30-
private $lowerMap = [];
30+
private array $lowerMap = [];
3131

3232
/**
3333
* @param array<string, array> $attributes

src/Symfony/Component/Ldap/Ldap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
final class Ldap implements LdapInterface
2424
{
25-
private $adapter;
25+
private AdapterInterface $adapter;
2626

2727
public function __construct(AdapterInterface $adapter)
2828
{

src/Symfony/Component/Ldap/Security/CheckLdapCredentialsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
class CheckLdapCredentialsListener implements EventSubscriberInterface
3030
{
31-
private $ldapLocator;
31+
private ContainerInterface $ldapLocator;
3232

3333
public function __construct(ContainerInterface $ldapLocator)
3434
{

src/Symfony/Component/Ldap/Security/LdapAuthenticator.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1818
use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface;
1919
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
20-
use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface;
2120

2221
/**
2322
* This class decorates internal authenticators to add the LDAP integration.
@@ -32,12 +31,12 @@
3231
*/
3332
class LdapAuthenticator implements AuthenticatorInterface
3433
{
35-
private $authenticator;
36-
private $ldapServiceId;
37-
private $dnString;
38-
private $searchDn;
39-
private $searchPassword;
40-
private $queryString;
34+
private AuthenticatorInterface $authenticator;
35+
private string $ldapServiceId;
36+
private string $dnString;
37+
private string $searchDn;
38+
private string $searchPassword;
39+
private string $queryString;
4140

4241
public function __construct(AuthenticatorInterface $authenticator, string $ldapServiceId, string $dnString = '{username}', string $searchDn = '', string $searchPassword = '', string $queryString = '')
4342
{

0 commit comments

Comments
 (0)
0