Skip to content

Commit

Permalink
Merge pull request #372 from villfa/fix/type
Browse files Browse the repository at this point in the history
Fix some type issues
  • Loading branch information
stevebauman committed Dec 14, 2021
2 parents b6e1d6f + 53d723f commit cece843
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
vendor
composer.lock
psalm.phar
.php_cs.cache
.phpunit.result.cache
.php-cs-fixer.cache
9 changes: 6 additions & 3 deletions src/Events/Logger.php
Expand Up @@ -39,11 +39,14 @@ public function log($event)
{
switch (true) {
case $event instanceof AuthEvent:
return $this->auth($event);
$this->auth($event);
break;
case $event instanceof ModelEvent:
return $this->model($event);
$this->model($event);
break;
case $event instanceof QueryEvent:
return $this->query($event);
$this->query($event);
break;
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/Events/NullDispatcher.php
Expand Up @@ -52,11 +52,11 @@ public function hasListeners($eventName)
* @param string|object $event
* @param mixed $payload
*
* @return array|null
* @return null
*/
public function until($event, $payload = [])
{
//
return null;
}

/**
Expand All @@ -66,11 +66,11 @@ public function until($event, $payload = [])
* @param mixed $payload
* @param bool $halt
*
* @return mixed
* @return null
*/
public function fire($event, $payload = [], $halt = false)
{
//
return null;
}

/**
Expand All @@ -80,11 +80,11 @@ public function fire($event, $payload = [], $halt = false)
* @param mixed $payload
* @param bool $halt
*
* @return array|null
* @return null
*/
public function dispatch($event, $payload = [], $halt = false)
{
//
return null;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/HandlesConnection.php
Expand Up @@ -157,12 +157,14 @@ public function getExtendedError()
protected function executeFailableOperation(Closure $operation)
{
// If some older versions of PHP, errors are reported instead of throwing
// exceptions, which could be a signifcant detriment to our application.
// exceptions, which could be a significant detriment to our application.
// Here, we will enforce these operations to throw exceptions instead.
set_error_handler(function ($severity, $message, $file, $line) {
set_error_handler(function (int $severity, string $message, string $file, int $line): bool {
if (! $this->shouldBypassError($message)) {
throw new ErrorException($message, $severity, $severity, $file, $line);
}

return true;
});

try {
Expand Down
4 changes: 2 additions & 2 deletions src/Ldap.php
Expand Up @@ -107,7 +107,7 @@ public function compare($dn, $attribute, $value)
public function getLastError()
{
if (! $this->connection) {
return;
return null;
}

return ldap_error($this->connection);
Expand All @@ -119,7 +119,7 @@ public function getLastError()
public function getDetailedError()
{
if (! $number = $this->errNo()) {
return;
return null;
}

$this->getOption(LDAP_OPT_DIAGNOSTIC_MESSAGE, $message);
Expand Down
10 changes: 5 additions & 5 deletions src/LdapInterface.php
Expand Up @@ -156,7 +156,7 @@ public function getLastError();
/**
* Return detailed information about an error.
*
* Returns false when there was a successful last request.
* Returns null when there was a successful last request.
*
* Returns DetailedError when there was an error.
*
Expand Down Expand Up @@ -292,10 +292,10 @@ public function read($dn, $filter, array $fields, $onlyAttributes = false, $size
*
* @param resource $result
* @param int $errorCode
* @param string $dn
* @param string $errorMessage
* @param array $referrals
* @param array $serverControls
* @param ?string $dn
* @param ?string $errorMessage
* @param ?array $referrals
* @param ?array $serverControls
*
* @return bool
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Models/Attributes/AccountControl.php
Expand Up @@ -53,14 +53,14 @@ class AccountControl
/**
* The account control flag values.
*
* @var array
* @var array<int, int>
*/
protected $values = [];

/**
* Constructor.
*
* @param int $flag
* @param ?int $flag
*/
public function __construct($flag = null)
{
Expand Down Expand Up @@ -431,7 +431,7 @@ public function getValue()
/**
* Get the account control flag values.
*
* @return array
* @return array<int, int>
*/
public function getValues()
{
Expand All @@ -441,7 +441,7 @@ public function getValues()
/**
* Set the account control values.
*
* @param array $flags
* @param array<int, int> $flags
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Attributes/DistinguishedName.php
Expand Up @@ -93,7 +93,7 @@ public static function isValid($value)
*/
public static function explode($dn)
{
$components = ldap_explode_dn($dn, $withoutAttributes = false);
$components = ldap_explode_dn($dn, (int) $withoutAttributes = false);

if (! is_array($components)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Attributes/DistinguishedNameBuilder.php
Expand Up @@ -236,7 +236,7 @@ public function get()
/**
* Build the distinguished name from the components.
*
* @return $this
* @return string
*/
protected function build()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Attributes/Timestamp.php
Expand Up @@ -155,7 +155,7 @@ public function toDateTime($value)
*
* @param string $value
*
* @return DateTime|bool
* @return DateTime|false
*/
protected function convertLdapTimeToDateTime($value)
{
Expand Down Expand Up @@ -184,7 +184,7 @@ protected function convertDateTimeToLdapTime(DateTime $date)
*
* @param string $value
*
* @return DateTime|bool
* @return DateTime|false
*/
protected function convertWindowsTimeToDateTime($value)
{
Expand Down Expand Up @@ -213,7 +213,7 @@ protected function convertDateTimeToWindows(DateTime $date)
*
* @param int $value
*
* @return DateTime|bool
* @return DateTime|false
*
* @throws \Exception
*/
Expand Down
3 changes: 3 additions & 0 deletions src/Models/Concerns/CanAuthenticate.php
Expand Up @@ -31,6 +31,7 @@ public function getAuthIdentifier()
*/
public function getAuthPassword()
{
return '';
}

/**
Expand All @@ -40,6 +41,7 @@ public function getAuthPassword()
*/
public function getRememberToken()
{
return '';
}

/**
Expand All @@ -60,5 +62,6 @@ public function setRememberToken($value)
*/
public function getRememberTokenName()
{
return '';
}
}
4 changes: 2 additions & 2 deletions src/Models/Model.php
Expand Up @@ -611,7 +611,7 @@ public function __unset($key)
/**
* Convert the model to its JSON encodeable array form.
*
* @return void
* @return array
*/
public function toArray()
{
Expand Down Expand Up @@ -884,7 +884,7 @@ public function newDn($dn = null)
/**
* Get the model's object GUID key.
*
* @return void
* @return string
*/
public function getObjectGuidKey()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Relations/OneToMany.php
Expand Up @@ -49,7 +49,7 @@ public function __construct(Builder $query, Model $parent, $related, $relationKe
/**
* Set the relation to load with its parent.
*
* @param OneToMany $relation
* @param Relation $relation
*
* @return $this
*/
Expand Down
1 change: 1 addition & 0 deletions src/Query/Collection.php
Expand Up @@ -13,6 +13,7 @@ class Collection extends BaseCollection
protected function valueRetriever($value)
{
if ($this->useAsCallable($value)) {
/** @var callable $value */
return $value;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Query/Events/QueryExecuted.php
Expand Up @@ -9,14 +9,14 @@ class QueryExecuted
/**
* The LDAP filter that was used for the query.
*
* @var string
* @var Builder
*/
protected $query;

/**
* The number of milliseconds it took to execute the query.
*
* @var float
* @var ?float
*/
protected $time;

Expand Down
4 changes: 2 additions & 2 deletions src/Query/ObjectNotFoundException.php
Expand Up @@ -23,8 +23,8 @@ class ObjectNotFoundException extends LdapRecordException
/**
* Create a new exception for the executed filter.
*
* @param string $query
* @param null $baseDn
* @param string $query
* @param ?string $baseDn
*
* @return static
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Pagination/AbstractPaginator.php
Expand Up @@ -106,7 +106,7 @@ abstract protected function applyServerControls(LdapInterface $ldap);
*
* @param LdapInterface $ldap
*
* @return mixed
* @return void
*/
abstract protected function resetServerControls(LdapInterface $ldap);

Expand Down
3 changes: 2 additions & 1 deletion src/Query/Pagination/Paginator.php
Expand Up @@ -37,7 +37,8 @@ protected function applyServerControls(LdapInterface $ldap)
*/
protected function updateServerControls(LdapInterface $ldap, $resource)
{
$errorCode = $dn = $errorMessage = $refs = null;
$errorCode = 0;
$dn = $errorMessage = $refs = null;

$ldap->parseResult(
$resource,
Expand Down

0 comments on commit cece843

Please sign in to comment.