8000 [Ldap] Backport refactorings · symfony/symfony@4d59096 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d59096

Browse files
committed
[Ldap] Backport refactorings
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 7c531f5 commit 4d59096

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class Query extends AbstractQuery
2424
// As of PHP 7.2, we can use LDAP_CONTROL_PAGEDRESULTS instead of this
2525
public const PAGINATION_OID = '1.2.840.113556.1.4.319';
2626

27-
/** @var Connection */
28-
protected $connection;
29-
3027
/** @var resource[] */
3128
private $results;
3229

@@ -156,17 +153,13 @@ public function execute()
156153
* Returns an LDAP search resource. If this query resulted in multiple searches, only the first
157154
* page will be returned.
158155
*
159-
* @return resource
156+
* @return resource|null
160157
*
161158
* @internal
162159
*/
163160
public function getResource(int $idx = 0)
164161
{
165-
if (null === $this->results || $idx >= \count($this->results)) {
166-
return null;
167-
}
168-
169-
return $this->results[$idx];
162+
return $this->results[$idx] ?? null;
170163
}
171164

172165
/**
@@ -259,9 +252,9 @@ private function controlPagedResultResponse($con, $result, string $cookie = ''):
259252
*
260253
* @param resource $con
261254
*
262-
* @return resource
255+
* @return resource|false
263256
*/
264-
private function callSearchFunction($con, string $func, int $sizeLimit)
257+
private function callSearchFunction($con, callable $func, int $sizeLimit)
265258
{
266259
if (\PHP_VERSION_ID < 70300) {
267260
return @$func($con, $this->dn, $this->query, $this->options['filter'], $this->options['attrsOnly'], $sizeLimit, $this->options['timeout'], $this->options['deref']);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class UpdateOperation
1919
private $values;
2020
private $attribute;
2121

22-
private $validOperationTypes = [
22+
private const VALID_OPERATION_TYPES = [
2323
\LDAP_MODIFY_BATCH_ADD,
2424
\LDAP_MODIFY_BATCH_REMOVE,
2525
\LDAP_MODIFY_BATCH_REMOVE_ALL,
@@ -34,7 +34,7 @@ class UpdateOperation
3434
*/
3535
public function __construct(int $operationType, string $attribute, ?array $values)
3636
{
37-
if (!\in_array($operationType, $this->validOperationTypes, true)) {
37+
if (!\in_array($operationType, self::VALID_OPERATION_TYPES, true)) {
3838
throw new UpdateOperationException(sprintf('"%s" is not a valid modification type.', $operationType));
3939
}
4040
if (\LDAP_MODIFY_BATCH_REMOVE_ALL === $operationType && null !== $values) {

src/Symfony/Component/Ldap/Entry.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@
1818
class Entry
1919
{
2020
private $dn;
21-
private $attributes;
22-
private $lowerMap;
2321

22+
/**
23+
* @var array<string, array>
24+
*/
25+
private $attributes = [];
26+
27+
/**
28+
* @var array<string, string>
29+
*/
30+
private $lowerMap = [];
31+
32+
/**
33+
* @param array<string, array> $attributes
34+
*/
2435
public function __construct(string $dn, array $attributes = [])
2536
{
2637
$this->dn = $dn;
27-
$this->attributes = [];
28-
$this->lowerMap = [];
2938

3039
foreach ($attributes as $key => $attribute) {
3140
$this->setAttribute($key, $attribute);

0 commit comments

Comments
 (0)
0