Skip to content

Commit

Permalink
Small refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Apr 17, 2023
1 parent b49e41a commit 488909e
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 30 deletions.
8 changes: 2 additions & 6 deletions src/Exceptions/ConstraintViolationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@ class ConstraintViolationException extends LdapRecordException
*/
public function causedByPasswordPolicy(): bool
{
return isset($this->detailedError)
? $this->errorContainsMessage($this->detailedError->getDiagnosticMessage(), '0000052D')
: false;
return isset($this->detailedError) && $this->errorContainsMessage($this->detailedError->getDiagnosticMessage(), '0000052D');
}

/**
* Determine if the exception was generated due to an incorrect password.
*/
public function causedByIncorrectPassword(): bool
{
return isset($this->detailedError)
? $this->errorContainsMessage($this->detailedError->getDiagnosticMessage(), '00000056')
: false;
return isset($this->detailedError) && $this->errorContainsMessage($this->detailedError->getDiagnosticMessage(), '00000056');
}
}
2 changes: 1 addition & 1 deletion src/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public function extractDiagnosticCode(string $message): string|false
{
preg_match('/^([\da-fA-F]+):/', $message, $matches);

return isset($matches[1]) ? $matches[1] : false;
return $matches[1] ?? false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Attributes/Guid.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Guid
*/
public static function isValid(string $guid): bool
{
return (bool) preg_match('/^([0-9a-fA-F]){8}(-([0-9a-fA-F]){4}){3}-([0-9a-fA-F]){12}$/', (string) $guid);
return (bool) preg_match('/^([0-9a-fA-F]){8}(-([0-9a-fA-F]){4}){3}-([0-9a-fA-F]){12}$/', $guid);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Attributes/Sid.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function binarySidToString(string $binary): string

$identifierAuthority = $sid['id'];

$subs = isset($sid['count']) ? $sid['count'] : 0;
$subs = $sid['count'] ?? 0;

$sidHex = $subs ? bin2hex($binary) : '';

Expand Down
2 changes: 1 addition & 1 deletion src/Models/BatchModification.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function setValues(array $values = []): static
// modification. Passing null or empty values will result
// in an exception when trying to save the modification.
$this->values = array_filter($this->normalizeAttributeValues($values), function ($value) {
return is_numeric($value) && $this->valueIsResetInteger((int) $value) ?: ! empty($value);
return is_numeric($value) && $this->valueIsResetInteger((int) $value) || ! empty($value);
});

return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,15 +498,15 @@ public function toJson(): string
/**
* Encode the given value as JSON.
*/
protected function asJson(mixed $value): string
protected function asJson(mixed $value): string|false
{
return json_encode($value);
}

/**
* Decode the given JSON back into an array or object.
*/
public function fromJson(string $value, bool $asObject = false)
public function fromJson(string $value, bool $asObject = false): mixed
{
return json_decode($value, ! $asObject);
}
Expand Down Expand Up @@ -567,7 +567,7 @@ protected function getArrayableItems(array $values): array
}

/**
* Get all of the appendable values that are arrayable.
* Get all the appendable values that are arrayable.
*/
protected function getArrayableAppends(): array
{
Expand Down
19 changes: 7 additions & 12 deletions src/Query/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,13 @@ protected function has(Builder $query, array|string $type, string $operator = '>
$filters += count($query->filters[$type]);
}

switch ($operator) {
case '>':
return $filters > $count;
case '>=':
return $filters >= $count;
case '<':
return $filters < $count;
case '<=':
return $filters <= $count;
default:
return $filters == $count;
}
return match ($operator) {
'>' => $filters > $count,
'>=' => $filters >= $count,
'<' => $filters < $count,
'<=' => $filters <= $count,
default => $filters == $count,
};
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Pagination/AbstractPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function execute(LdapInterface $ldap): mixed
}

/**
* Whether the paginater should continue iterating.
* Whether the paginator should continue iterating.
*/
protected function shouldContinue(): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function afterLast(string $subject, string $search): string
return $subject;
}

$position = strrpos($subject, (string) $search);
$position = strrpos($subject, $search);

if ($position === false) {
return $subject;
Expand Down
4 changes: 1 addition & 3 deletions src/Testing/LdapExpectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LdapExpectation
/**
* The method that the expectation belongs to.
*/
protected string $method;
protected ?string $method = null;

/**
* The methods argument's.
Expand All @@ -50,8 +50,6 @@ class LdapExpectation

/**
* The error number to return.
*
* @var int
*/
protected ?string $errorCode = null;

Expand Down

0 comments on commit 488909e

Please sign in to comment.