Skip to content

Commit

Permalink
More strict types and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Apr 17, 2023
1 parent e329785 commit c91d7f5
Show file tree
Hide file tree
Showing 30 changed files with 293 additions and 880 deletions.
3 changes: 3 additions & 0 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Carbon\Carbon;
use Closure;
use LdapRecord\Auth\Guard;
use LdapRecord\Configuration\ConfigurationException;
use LdapRecord\Configuration\DomainConfiguration;
use LdapRecord\Events\DispatcherInterface;
use LdapRecord\Query\Builder;
Expand Down Expand Up @@ -67,6 +68,8 @@ class Connection

/**
* Constructor.
*
* @throws ConfigurationException
*/
public function __construct(DomainConfiguration|array $config = [], LdapInterface $ldap = null)
{
Expand Down
36 changes: 10 additions & 26 deletions src/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LdapRecord\Events;

use Closure;
use LdapRecord\Support\Arr;
use LdapRecord\Support\Str;

Expand Down Expand Up @@ -62,9 +63,9 @@ protected function setupWildcardListen(string $event, mixed $listener): void
/**
* {@inheritdoc}
*/
public function hasListeners(string $eventName): bool
public function hasListeners(string $event): bool
{
return isset($this->listeners[$eventName]) || isset($this->wildcards[$eventName]);
return isset($this->listeners[$event]) || isset($this->wildcards[$event]);
}

/**
Expand Down Expand Up @@ -168,11 +169,8 @@ protected function getWildcardListeners(string $event): array

/**
* Add the listeners for the event's interfaces to the given array.
*
* @param string $eventName
* @return array
*/
protected function addInterfaceListeners($eventName, array $listeners = [])
protected function addInterfaceListeners(string $eventName, array $listeners = []): array
{
foreach (class_implements($eventName) as $interface) {
if (isset($this->listeners[$interface])) {
Expand All @@ -187,12 +185,8 @@ protected function addInterfaceListeners($eventName, array $listeners = [])

/**
* Register an event listener with the dispatcher.
*
* @param \Closure|string $listener
* @param bool $wildcard
* @return \Closure
*/
public function makeListener($listener, $wildcard = false)
public function makeListener(Closure|string $listener, bool $wildcard = false): Closure
{
if (is_string($listener)) {
return $this->createClassListener($listener, $wildcard);
Expand All @@ -209,12 +203,8 @@ public function makeListener($listener, $wildcard = false)

/**
* Create a class based listener.
*
* @param string $listener
* @param bool $wildcard
* @return \Closure
*/
protected function createClassListener($listener, $wildcard = false)
protected function createClassListener(string $listener, bool $wildcard = false): Closure
{
return function ($event, $payload) use ($listener, $wildcard) {
if ($wildcard) {
Expand All @@ -230,11 +220,8 @@ protected function createClassListener($listener, $wildcard = false)

/**
* Create the class based event callable.
*
* @param string $listener
* @return callable
*/
protected function createClassCallable($listener)
protected function createClassCallable(string $listener): callable
{
[$class, $method] = $this->parseListenerCallback($listener);

Expand All @@ -243,13 +230,10 @@ protected function createClassCallable($listener)

/**
* Parse the class listener into class and method.
*
* @param string $listener
* @return array
*/
protected function parseListenerCallback($listener)
protected function parseListenerCallback(string $listener): array
{
return str_contains((string) $listener, '@')
return str_contains($listener, '@')
? explode('@', $listener, 2)
: [$listener, 'handle'];
}
Expand All @@ -259,7 +243,7 @@ protected function parseListenerCallback($listener)
*/
public function forget(string $event): void
{
if (str_contains((string) $event, '*')) {
if (str_contains($event, '*')) {
unset($this->wildcards[$event]);
} else {
unset($this->listeners[$event]);
Expand Down
2 changes: 2 additions & 0 deletions src/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ public function getExtendedErrorHex(): ?string
if (preg_match("/(?<=data\s).*?(?=,)/", $this->getExtendedError(), $code)) {
return $code[0];
}

return null;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Models/ActiveDirectory/Concerns/HasPrimaryGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ trait HasPrimaryGroup
{
/**
* Returns a new has one primary group relationship.
*
* @param string $relationKey
* @param string $foreignKey
* @return HasOnePrimaryGroup
*/
public function hasOnePrimaryGroup($related, $relationKey, $foreignKey = 'primarygroupid')
public function hasOnePrimaryGroup(string $related, string $relationKey, string $foreignKey = 'primarygroupid'): HasOnePrimaryGroup
{
return new HasOnePrimaryGroup($this->newQuery(), $this, $related, $relationKey, $foreignKey);
}
Expand Down
13 changes: 3 additions & 10 deletions src/Models/ActiveDirectory/Relations/HasOnePrimaryGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class HasOnePrimaryGroup extends HasOne
{
/**
* Get the foreign model by the given value.
*
* @param string $value
* @return Model|null
*/
protected function getForeignModelByValue($value)
protected function getForeignModelByValue(string $value): ?Model
{
return $this->query->findBySid(
$this->getParentModelObjectSid()
Expand All @@ -24,10 +21,8 @@ protected function getForeignModelByValue($value)
* Get the foreign value from the given model.
*
* Retrieves the last RID from the models Object SID.
*
* @return string
*/
protected function getForeignValueFromModel(Model $model)
protected function getForeignValueFromModel(Model $model): ?string
{
$objectSidComponents = explode('-', $model->getConvertedSid());

Expand All @@ -36,10 +31,8 @@ protected function getForeignValueFromModel(Model $model)

/**
* Get the parent relationship models converted object sid.
*
* @return string
*/
protected function getParentModelObjectSid()
protected function getParentModelObjectSid(): string
{
return preg_replace(
'/\d+$/',
Expand Down
Loading

0 comments on commit c91d7f5

Please sign in to comment.