Skip to content

Commit

Permalink
Use constructor property promotion and readonly properties where poss…
Browse files Browse the repository at this point in the history
…ible.
  • Loading branch information
ChadSikorra committed Jul 11, 2023
1 parent 31abdbc commit ceeec93
Show file tree
Hide file tree
Showing 50 changed files with 111 additions and 397 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"phpunit"
],
"analyse": [
"phpstan analyse"
"phpstan --memory-limit=-1 analyse"
],
"analyse-tests": [
"phpstan analyse -c phpstan.tests.neon"
Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Ad/DirSyncRequestControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,11 @@ class DirSyncRequestControl extends Control
*/
public const FLAG_INCREMENTAL_VALUES = -0x80000000;

private int $flags;

private int $maxBytes;

private string $cookie;

public function __construct(
int $flags = self::FLAG_INCREMENTAL_VALUES,
string $cookie = '',
int $maxBytes = 2147483647
private int $flags = self::FLAG_INCREMENTAL_VALUES,
private string $cookie = '',
private int $maxBytes = 2147483647
) {
$this->flags = $flags;
$this->maxBytes = $maxBytes;
$this->cookie = $cookie;
parent::__construct(
self::OID_DIR_SYNC,
true
Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Ad/DirSyncResponseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,11 @@
*/
class DirSyncResponseControl extends Control
{
private int $moreResults;

private int $unused;

private string $cookie;

public function __construct(
int $moreResults,
int $unused = 0,
string $cookie = ''
private readonly int $moreResults,
private readonly int $unused = 0,
private readonly string $cookie = ''
) {
$this->moreResults = $moreResults;
$this->unused = $unused;
$this->cookie = $cookie;
parent::__construct(self::OID_DIR_SYNC);
}

Expand Down
25 changes: 10 additions & 15 deletions src/FreeDSx/Ldap/Control/Ad/ExpectedEntryCountControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
use FreeDSx\Ldap\Exception\ProtocolException;

/**
* Represents an Expected Entry Count control. Defined in MS-ADTS 3.1.1.3.4.1.33. The control value request definition is:
* Represents an Expected Entry Count control. Defined in MS-ADTS 3.1.1.3.4.1.33. The control value request definition
* is:
*
* ExpectedEntryCountRequestValue ::= SEQUENCE {
* searchEntriesMin INTEGER
Expand All @@ -35,16 +36,10 @@
*/
class ExpectedEntryCountControl extends Control
{
private int $minimum;

private int $maximum;

public function __construct(
int $min,
int $max
private int $min,
private int $max,
) {
$this->minimum = $min;
$this->maximum = $max;
parent::__construct(
self::OID_EXPECTED_ENTRY_COUNT,
true
Expand All @@ -53,24 +48,24 @@ public function __construct(

public function getMaximum(): int
{
return $this->maximum;
return $this->max;
}

public function setMaximum(int $max): self
{
$this->maximum = $max;
$this->max = $max;

return $this;
}

public function getMinimum(): int
{
return $this->minimum;
return $this->min;
}

public function setMinimum(int $min): self
{
$this->minimum = $min;
$this->min = $min;

return $this;
}
Expand Down Expand Up @@ -111,8 +106,8 @@ public static function fromAsn1(AbstractType $type): static
public function toAsn1(): AbstractType
{
$this->controlValue = Asn1::sequence(
Asn1::integer($this->minimum),
Asn1::integer($this->maximum)
Asn1::integer($this->min),
Asn1::integer($this->max)
);

return parent::toAsn1();
Expand Down
5 changes: 1 addition & 4 deletions src/FreeDSx/Ldap/Control/Ad/ExtendedDnControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
*/
class ExtendedDnControl extends Control
{
private bool $useHexFormat;

public function __construct(bool $useHexFormat = false)
public function __construct(private bool $useHexFormat = false)
{
$this->useHexFormat = $useHexFormat;
parent::__construct(self::OID_EXTENDED_DN);
}

Expand Down
5 changes: 1 addition & 4 deletions src/FreeDSx/Ldap/Control/Ad/PolicyHintsControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@
*/
class PolicyHintsControl extends Control
{
private bool $isEnabled;

public function __construct(bool $isEnabled = true)
public function __construct(private bool $isEnabled = true)
{
$this->isEnabled = $isEnabled;
parent::__construct(
self::OID_POLICY_HINTS,
true
Expand Down
5 changes: 1 addition & 4 deletions src/FreeDSx/Ldap/Control/Ad/SdFlagsControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ class SdFlagsControl extends Control
*/
public const SACL_SECURITY_INFORMATION = 8;

private int $flags;

public function __construct(int $flags)
public function __construct(private int $flags)
{
$this->flags = $flags;
parent::__construct(self::OID_SD_FLAGS);
}

Expand Down
4 changes: 1 addition & 3 deletions src/FreeDSx/Ldap/Control/Ad/SetOwnerControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
*/
class SetOwnerControl extends Control
{
private string $sid;

public function __construct(string $sid)
public function __construct(private string $sid)
{
$this->sid = $sid;
parent::__construct(
Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Control.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,11 @@ class Control implements ProtocolElementInterface, Stringable

public const OID_VLV_RESPONSE = '2.16.840.1.113730.3.4.10';

protected string $controlType;

protected bool $criticality;

protected AbstractType|ProtocolElementInterface|string|null $controlValue;

public function __construct(
string $controlType,
bool $criticality = false,
AbstractType|ProtocolElementInterface|string|null $controlValue = null
protected string $controlType,
protected bool $criticality = false,
protected AbstractType|ProtocolElementInterface|string|null $controlValue = null
) {
$this->controlType = $controlType;
$this->criticality = $criticality;
$this->controlValue = $controlValue;
}

public function setTypeOid(string $oid): static
Expand Down
10 changes: 2 additions & 8 deletions src/FreeDSx/Ldap/Control/PagingControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,10 @@
*/
class PagingControl extends Control
{
private string $cookie;

private int $size;

public function __construct(
int $size,
string $cookie = ''
private int $size,
private string $cookie = ''
) {
$this->size = $size;
$this->cookie = $cookie;
parent::__construct(self::OID_PAGING);
}

Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/PwdPolicyResponseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,11 @@
*/
class PwdPolicyResponseControl extends Control
{
private ?int $timeBeforeExpiration;

private ?int $graceAuthRemaining;

private ?int $error;

public function __construct(
?int $timeBeforeExpiration = null,
?int $graceAuthRemaining = null,
?int $error = null
private readonly ?int $timeBeforeExpiration = null,
private readonly ?int $graceAuthRemaining = null,
private readonly ?int $error = null
) {
$this->timeBeforeExpiration = $timeBeforeExpiration;
$this->graceAuthRemaining = $graceAuthRemaining;
$this->error = $error;
parent::__construct(self::OID_PWD_POLICY);
}

Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Sorting/SortKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@
*/
class SortKey
{
private string $attribute;

private ?string $orderingRule;

private bool $useReverseOrder;

public function __construct(
string $attribute,
bool $useReverseOrder = false,
?string $orderingRule = null
private string $attribute,
private bool $useReverseOrder = false,
private ?string $orderingRule = null
) {
$this->attribute = $attribute;
$this->orderingRule = $orderingRule;
$this->useReverseOrder = $useReverseOrder;
}

public function getAttribute(): string
Expand Down
10 changes: 2 additions & 8 deletions src/FreeDSx/Ldap/Control/Sorting/SortingResponseControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@
*/
class SortingResponseControl extends Control
{
private int $result;

private ?string $attribute;

public function __construct(
int $result,
?string $attribute = null
private readonly int $result,
private readonly ?string $attribute = null
) {
$this->result = $result;
$this->attribute = $attribute;
parent::__construct(self::OID_SORTING_RESPONSE);
}

Expand Down
9 changes: 1 addition & 8 deletions src/FreeDSx/Ldap/Control/SubentriesControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@
*/
class SubentriesControl extends Control
{
private bool $isVisible;

/**
* @param bool $isVisible
*/
public function __construct(bool $isVisible = true)
public function __construct(private bool $isVisible = true)
{
$this->isVisible = $isVisible;

parent::__construct(
self::OID_SUBENTRIES,
true
Expand Down
11 changes: 2 additions & 9 deletions src/FreeDSx/Ldap/Control/Sync/SyncDoneControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,10 @@
*/
class SyncDoneControl extends Control
{
private ?string $cookie;

private bool $refreshDeletes;

public function __construct(
?string $cookie = null,
bool $refreshDeletes = false,
private readonly ?string $cookie = null,
private readonly bool $refreshDeletes = false,
) {
$this->cookie = $cookie;
$this->refreshDeletes = $refreshDeletes;

parent::__construct(
self::OID_SYNC_DONE,
true
Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Sync/SyncRequestControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,11 @@ class SyncRequestControl extends Control

public const MODE_REFRESH_AND_PERSIST = 3;

private int $mode;

private ?string $cookie;

private bool $reloadHint;

public function __construct(
int $mode = self::MODE_REFRESH_ONLY,
?string $cookie = null,
bool $reloadHint = false
private int $mode = self::MODE_REFRESH_ONLY,
private ?string $cookie = null,
private bool $reloadHint = false
) {
$this->mode = $mode;
$this->cookie = $cookie;
$this->reloadHint = $reloadHint;
parent::__construct(
self::OID_SYNC_REQUEST,
true
Expand Down
15 changes: 3 additions & 12 deletions src/FreeDSx/Ldap/Control/Sync/SyncStateControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,13 @@ class SyncStateControl extends Control

public const STATE_DELETE = 3;

private int $state;

private ?string $cookie;

private string $entryUuid;

private ?string $decodedUuid = null;

public function __construct(
int $state,
string $entryUuid,
?string $cookie = null
private readonly int $state,
private readonly string $entryUuid,
private readonly ?string $cookie = null
) {
$this->state = $state;
$this->cookie = $cookie;
$this->entryUuid = $entryUuid;
parent::__construct(self::OID_SYNC_STATE);
}

Expand Down
Loading

0 comments on commit ceeec93

Please sign in to comment.