Skip to content

Commit d8831c0

Browse files
committed
use constructor property promotion
1 parent 4fd7d8c commit d8831c0

11 files changed

+65
-106
lines changed

Adapter/AbstractQuery.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
*/
2020
abstract class AbstractQuery implements QueryInterface
2121
{
22-
protected ConnectionInterface $connection;
23-
protected string $dn;
24-
protected string $query;
2522
protected array $options;
2623

27-
public function __construct(ConnectionInterface $connection, string $dn, string $query, array $options = [])
28-
{
24+
public function __construct(
25+
protected ConnectionInterface $connection,
26+
protected string $dn,
27+
protected string $query,
28+
array $options = [],
29+
) {
2930
$resolver = new OptionsResolver();
3031
$resolver->setDefaults([
3132
'filter' => '*',
@@ -42,9 +43,6 @@ public function __construct(ConnectionInterface $connection, string $dn, string
4243

4344
$resolver->setNormalizer('filter', fn (Options $options, $value) => \is_array($value) ? $value : [$value]);
4445

45-
$this->connection = $connection;
46-
$this->dn = $dn;
47-
$this->query = $query;
4846
$this->options = $resolver->resolve($options);
4947
}
5048
}

Adapter/ExtLdap/Adapter.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@
2222
*/
2323
class Adapter implements AdapterInterface
2424
{
25-
private array $config;
2625
private ConnectionInterface $connection;
2726
private EntryManagerInterface $entryManager;
2827

29-
public function __construct(array $config = [])
30-
{
28+
public function __construct(
29+
private array $config = [],
30+
) {
3131
if (!\extension_loaded('ldap')) {
3232
throw new LdapException('The LDAP PHP extension is not enabled.');
3333
}
34-
35-
$this->config = $config;
3634
}
3735

3836
public function getConnection(): ConnectionInterface

Adapter/ExtLdap/Collection.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
*/
2121
class Collection implements CollectionInterface
2222
{
23-
private Connection $connection;
24-
private Query $search;
2523
/** @var list<Entry> */
2624
private array $entries;
2725

28-
public function __construct(Connection $connection, Query $search)
29-
{
30-
$this->connection = $connection;
31-
$this->search = $search;
26+
public function __construct(
27+
private Connection $connection,
28+
private Query $search,
29+
) {
3230
}
3331

3432
public function toArray(): array

Adapter/ExtLdap/UpdateOperation.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515

1616
class UpdateOperation
1717
{
18-
private int $operationType;
19-
private ?array $values;
20-
private string $attribute;
21-
2218
private const VALID_OPERATION_TYPES = [
2319
\LDAP_MODIFY_BATCH_ADD,
2420
\LDAP_MODIFY_BATCH_REMOVE,
@@ -32,18 +28,17 @@ class UpdateOperation
3228
*
3329
* @throws UpdateOperationException on consistency errors during construction
3430
*/
35-
public function __construct(int $operationType, string $attribute, ?array $values)
36-
{
31+
public function __construct(
32+
private int $operationType,
33+
private string $attribute,
34+
private ?array $values,
35+
) {
3736
if (!\in_array($operationType, self::VALID_OPERATION_TYPES, true)) {
3837
throw new UpdateOperationException(sprintf('"%s" is not a valid modification type.', $operationType));
3938
}
4039
if (\LDAP_MODIFY_BATCH_REMOVE_ALL === $operationType && null !== $values) {
4140
throw new UpdateOperationException(sprintf('$values must be null for LDAP_MODIFY_BATCH_REMOVE_ALL operation, "%s" given.', get_debug_type($values)));
4241
}
43-
44-
$this->operationType = $operationType;
45-
$this->attribute = $attribute;
46-
$this->values = $values;
4742
}
4843

4944
public function toArray(): array

Entry.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818
class Entry
1919
{
20-
private string $dn;
21-
2220
/**
2321
* @var array<string, array>
2422
*/
@@ -32,10 +30,10 @@ class Entry
3230
/**
3331
* @param array<string, array> $attributes
3432
*/
35-
public function __construct(string $dn, array $attributes = [])
36-
{
37-
$this->dn = $dn;
38-
33+
public function __construct(
34+
private string $dn,
35+
array $attributes = [],
36+
) {
3937
foreach ($attributes as $key => $attribute) {
4038
$this->setAttribute($key, $attribute);
4139
}

Ldap.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
*/
2323
final class Ldap implements LdapInterface
2424
{
25-
private AdapterInterface $adapter;
26-
27-
public function __construct(AdapterInterface $adapter)
28-
{
29-
$this->adapter = $adapter;
25+
public function __construct(
26+
private AdapterInterface $adapter,
27+
) {
3028
}
3129

3230
public function bind(?string $dn = null, #[\SensitiveParameter] ?string $password = null): void

Security/CheckLdapCredentialsListener.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
*/
3030
class CheckLdapCredentialsListener implements EventSubscriberInterface
3131
{
32-
private ContainerInterface $ldapLocator;
33-
34-
public function __construct(ContainerInterface $ldapLocator)
35-
{
36-
$this->ldapLocator = $ldapLocator;
32+
public function __construct(
33+
private ContainerInterface $ldapLocator,
34+
) {
3735
}
3836

3937
public function onCheckPassport(CheckPassportEvent $event): void

Security/LdapAuthenticator.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,14 @@
3434
*/
3535
class LdapAuthenticator implements AuthenticationEntryPointInterface, InteractiveAuthenticatorInterface
3636
{
37-
private AuthenticatorInterface $authenticator;
38-
private string $ldapServiceId;
39-
private string $dnString;
40-
private string $searchDn;
41-
private string $searchPassword;
42-
private string $queryString;
43-
44-
public function __construct(AuthenticatorInterface $authenticator, string $ldapServiceId, string $dnString = '{user_identifier}', string $searchDn = '', string $searchPassword = '', string $queryString = '')
45-
{
46-
$this->authenticator = $authenticator;
47-
$this->ldapServiceId = $ldapServiceId;
48-
$this->dnString = $dnString;
49-
$this->searchDn = $searchDn;
50-
$this->searchPassword = $searchPassword;
51-
$this->queryString = $queryString;
37+
public function __construct(
38+
private AuthenticatorInterface $authenticator,
39+
private string $ldapServiceId,
40+
private string $dnString = '{user_identifier}',
41+
private string $searchDn = '',
42+
private string $searchPassword = '',
43+
private string $queryString = '',
44+
) {
5245
}
5346

5447
public function supports(Request $request): ?bool

Security/LdapBadge.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@
2525
class LdapBadge implements BadgeInterface
2626
{
2727
private bool $resolved = false;
28-
private string $ldapServiceId;
29-
private string $dnString;
30-
private string $searchDn;
31-
private string $searchPassword;
32-
private ?string $queryString;
28+
private string $queryString;
3329

34-
public function __construct(string $ldapServiceId, string $dnString = '{user_identifier}', string $searchDn = '', string $searchPassword = '', ?string $queryString = null)
35-
{
36-
$this->ldapServiceId = $ldapServiceId;
37-
$this->dnString = $dnString;
38-
$this->searchDn = $searchDn;
39-
$this->searchPassword = $searchPassword;
30+
public function __construct(
31+
private string $ldapServiceId,
32+
private string $dnString = '{user_identifier}',
33+
private string $searchDn = '',
34+
private string $searchPassword = '',
35+
?string $queryString = null,
36+
) {
4037
$this->queryString = $queryString ?? '';
4138
}
4239

@@ -60,7 +57,7 @@ public function getSearchPassword(): string
6057
return $this->searchPassword;
6158
}
6259

63-
public function getQueryString(): ?string
60+
public function getQueryString(): string
6461
{
6562
return $this->queryString;
6663
}

Security/LdapUser.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@
2323
*/
2424
class LdapUser implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
2525
{
26-
private Entry $entry;
27-
private string $identifier;
28-
private ?string $password;
29-
private array $roles;
30-
private array $extraFields;
31-
32-
public function __construct(Entry $entry, string $identifier, #[\SensitiveParameter] ?string $password, array $roles = [], array $extraFields = [])
33-
{
26+
public function __construct(
27+
private Entry $entry,
28+
private string $identifier,
29+
#[\SensitiveParameter] private ?string $password,
30+
private array $roles = [],
31+
private array $extraFields = [],
32+
) {
3433
if (!$identifier) {
3534
throw new \InvalidArgumentException('The username cannot be empty.');
3635
}
37-
38-
$this->entry = $entry;
39-
$this->identifier = $identifier;
40-
$this->password = $password;
41-
$this->roles = $roles;
42-
$this->extraFields = $extraFields;
4336
}
4437

4538
public function getEntry(): Entry

0 commit comments

Comments
 (0)