Skip to content

Commit c937fd5

Browse files
Add types to private and internal properties
1 parent 485dd1f commit c937fd5

File tree

4 files changed

+14
-51
lines changed

4 files changed

+14
-51
lines changed

Adapter/ExtLdap/Connection.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ class Connection extends AbstractConnection
3737
];
3838

3939
private bool $bound = false;
40-
41-
/** @var resource|LDAPConnection */
42-
private $connection;
40+
private ?LDAPConnection $connection = null;
4341

4442
public function __sleep(): array
4543
{
@@ -92,11 +90,9 @@ public function bind(string $dn = null, #[\SensitiveParameter] string $password
9290
}
9391

9492
/**
95-
* @return resource|LDAPConnection
96-
*
9793
* @internal
9894
*/
99-
public function getResource()
95+
public function getResource(): ?LDAPConnection
10096
{
10197
return $this->connection;
10298
}

Adapter/ExtLdap/EntryManager.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@
2424
*/
2525
class EntryManager implements EntryManagerInterface
2626
{
27-
private Connection $connection;
28-
29-
public function __construct(Connection $connection)
30-
{
31-
$this->connection = $connection;
27+
public function __construct(
28+
private Connection $connection,
29+
) {
3230
}
3331

3432
/**
@@ -135,8 +133,8 @@ public function rename(Entry $entry, string $newRdn, bool $removeOldRdn = true)
135133
*/
136134
public function move(Entry $entry, string $newParent)
137135
{
138-
$con = $this->getConnectionResource();
139136
$rdn = $this->parseRdnFromEntry($entry);
137+
$con = $this->getConnectionResource();
140138
// deleteOldRdn does not matter here, since the Rdn will not be changing in the move.
141139
if (!@ldap_rename($con, $entry->getDn(), $rdn, $newParent, true)) {
142140
throw new LdapException(sprintf('Could not move entry "%s" to "%s": ', $entry->getDn(), $newParent).ldap_error($con), ldap_errno($con));
@@ -147,10 +145,8 @@ public function move(Entry $entry, string $newParent)
147145

148146
/**
149147
* Get the connection resource, but first check if the connection is bound.
150-
*
151-
* @return resource|LDAPConnection
152148
*/
153-
private function getConnectionResource()
149+
private function getConnectionResource(): LDAPConnection
154150
{
155151
// If the connection is not bound, throw an exception. Users should use an explicit bind call first.
156152
if (!$this->connection->isBound()) {

Adapter/ExtLdap/Query.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Ldap\Adapter\ExtLdap;
1313

14-
use LDAP\Connection as LDAPConnection;
1514
use LDAP\Result;
1615
use Symfony\Component\Ldap\Adapter\AbstractQuery;
1716
use Symfony\Component\Ldap\Adapter\CollectionInterface;
@@ -26,7 +25,7 @@ class Query extends AbstractQuery
2625
{
2726
public const PAGINATION_OID = \LDAP_CONTROL_PAGEDRESULTS;
2827

29-
/** @var resource[]|Result[] */
28+
/** @var Result[] */
3029
private array $results;
3130

3231
private array $serverctrls = [];
@@ -102,7 +101,7 @@ public function execute(): CollectionInterface
102101
if ($pageSize > 0 && $sizeLimit >= $pageSize) {
103102
$sizeLimit = 0;
104103
}
105-
$search = $this->callSearchFunction($con, $func, $sizeLimit);
104+
$search = @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref'], $this->serverctrls);
106105

107106
if (false === $search) {
108107
$ldapError = '';
@@ -123,7 +122,9 @@ public function execute(): CollectionInterface
123122
break;
124123
}
125124
if ($pageControl) {
126-
$cookie = $this->controlPagedResultResponse($con, $search);
125+
ldap_parse_result($con, $search, $errcode, $matcheddn, $errmsg, $referrals, $controls);
126+
127+
$cookie = $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
127128
}
128129
} while (null !== $cookie && '' !== $cookie);
129130

@@ -139,19 +140,17 @@ public function execute(): CollectionInterface
139140
* Returns an LDAP search resource. If this query resulted in multiple searches, only the first
140141
* page will be returned.
141142
*
142-
* @return resource|Result|null
143-
*
144143
* @internal
145144
*/
146-
public function getResource(int $idx = 0)
145+
public function getResource(int $idx = 0): ?Result
147146
{
148147
return $this->results[$idx] ?? null;
149148
}
150149

151150
/**
152151
* Returns all LDAP search resources.
153152
*
154-
* @return resource[]|Result[]
153+
* @return Result[]
155154
*
156155
* @internal
157156
*/
@@ -209,29 +208,4 @@ private function controlPagedResult(int $pageSize, bool $critical, string $cooki
209208

210209
return true;
211210
}
212-
213-
/**
214-
* Retrieve LDAP pagination cookie.
215-
*
216-
* @param resource|LDAPConnection $con
217-
* @param resource|Result $result
218-
*/
219-
private function controlPagedResultResponse($con, $result): string
220-
{
221-
ldap_parse_result($con, $result, $errcode, $matcheddn, $errmsg, $referrals, $controls);
222-
223-
return $controls[\LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
224-
}
225-
226-
/**
227-
* Calls actual LDAP search function with the prepared options and parameters.
228-
*
229-
* @param resource|LDAPConnection $con
230-
*
231-
* @return resource|Result|false
232-
*/
233-
private function callSearchFunction($con, callable $func, int $sizeLimit)
234-
{
235-
return @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref'], $this->serverctrls);
236-
}
237211
}

Tests/Adapter/ExtLdap/EntryManagerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public function testMove()
2525
$this->expectException(LdapException::class);
2626
$this->expectExceptionMessage('Entry "$$$$$$" malformed, could not parse RDN.');
2727
$connection = $this->createMock(Connection::class);
28-
$connection
29-
->expects($this->once())
30-
->method('isBound')->willReturn(true);
3128

3229
$entry = new Entry('$$$$$$');
3330
$entryManager = new EntryManager($connection);

0 commit comments

Comments
 (0)