diff --git a/.gitignore b/.gitignore index d5389fd6..e288894f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ vendor composer.lock +psalm.phar .php_cs.cache .phpunit.result.cache .php-cs-fixer.cache \ No newline at end of file diff --git a/src/Events/Logger.php b/src/Events/Logger.php index f3840c28..b2082e59 100644 --- a/src/Events/Logger.php +++ b/src/Events/Logger.php @@ -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; } } diff --git a/src/Events/NullDispatcher.php b/src/Events/NullDispatcher.php index 952f302f..73b1f5a8 100644 --- a/src/Events/NullDispatcher.php +++ b/src/Events/NullDispatcher.php @@ -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; } /** @@ -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; } /** @@ -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; } /** diff --git a/src/HandlesConnection.php b/src/HandlesConnection.php index 8924aefc..9af7ad75 100644 --- a/src/HandlesConnection.php +++ b/src/HandlesConnection.php @@ -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 { diff --git a/src/Ldap.php b/src/Ldap.php index 42cf4f1f..0c3574f1 100644 --- a/src/Ldap.php +++ b/src/Ldap.php @@ -107,7 +107,7 @@ public function compare($dn, $attribute, $value) public function getLastError() { if (! $this->connection) { - return; + return null; } return ldap_error($this->connection); @@ -119,7 +119,7 @@ public function getLastError() public function getDetailedError() { if (! $number = $this->errNo()) { - return; + return null; } $this->getOption(LDAP_OPT_DIAGNOSTIC_MESSAGE, $message); diff --git a/src/LdapInterface.php b/src/LdapInterface.php index 4ebf2c44..c74fe4e8 100644 --- a/src/LdapInterface.php +++ b/src/LdapInterface.php @@ -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. * @@ -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 */ diff --git a/src/Models/Attributes/AccountControl.php b/src/Models/Attributes/AccountControl.php index 9c6240bc..7e241462 100644 --- a/src/Models/Attributes/AccountControl.php +++ b/src/Models/Attributes/AccountControl.php @@ -53,14 +53,14 @@ class AccountControl /** * The account control flag values. * - * @var array + * @var array */ protected $values = []; /** * Constructor. * - * @param int $flag + * @param ?int $flag */ public function __construct($flag = null) { @@ -431,7 +431,7 @@ public function getValue() /** * Get the account control flag values. * - * @return array + * @return array */ public function getValues() { @@ -441,7 +441,7 @@ public function getValues() /** * Set the account control values. * - * @param array $flags + * @param array $flags * * @return void */ diff --git a/src/Models/Attributes/DistinguishedName.php b/src/Models/Attributes/DistinguishedName.php index 67650168..c6977a8e 100644 --- a/src/Models/Attributes/DistinguishedName.php +++ b/src/Models/Attributes/DistinguishedName.php @@ -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 []; diff --git a/src/Models/Attributes/DistinguishedNameBuilder.php b/src/Models/Attributes/DistinguishedNameBuilder.php index 83dfe716..601902bf 100644 --- a/src/Models/Attributes/DistinguishedNameBuilder.php +++ b/src/Models/Attributes/DistinguishedNameBuilder.php @@ -236,7 +236,7 @@ public function get() /** * Build the distinguished name from the components. * - * @return $this + * @return string */ protected function build() { diff --git a/src/Models/Attributes/Timestamp.php b/src/Models/Attributes/Timestamp.php index b12fc6fb..e5d9dc34 100644 --- a/src/Models/Attributes/Timestamp.php +++ b/src/Models/Attributes/Timestamp.php @@ -155,7 +155,7 @@ public function toDateTime($value) * * @param string $value * - * @return DateTime|bool + * @return DateTime|false */ protected function convertLdapTimeToDateTime($value) { @@ -184,7 +184,7 @@ protected function convertDateTimeToLdapTime(DateTime $date) * * @param string $value * - * @return DateTime|bool + * @return DateTime|false */ protected function convertWindowsTimeToDateTime($value) { @@ -213,7 +213,7 @@ protected function convertDateTimeToWindows(DateTime $date) * * @param int $value * - * @return DateTime|bool + * @return DateTime|false * * @throws \Exception */ diff --git a/src/Models/Concerns/CanAuthenticate.php b/src/Models/Concerns/CanAuthenticate.php index f287454e..451738ab 100644 --- a/src/Models/Concerns/CanAuthenticate.php +++ b/src/Models/Concerns/CanAuthenticate.php @@ -31,6 +31,7 @@ public function getAuthIdentifier() */ public function getAuthPassword() { + return ''; } /** @@ -40,6 +41,7 @@ public function getAuthPassword() */ public function getRememberToken() { + return ''; } /** @@ -60,5 +62,6 @@ public function setRememberToken($value) */ public function getRememberTokenName() { + return ''; } } diff --git a/src/Models/Model.php b/src/Models/Model.php index 61303670..2e11696b 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -611,7 +611,7 @@ public function __unset($key) /** * Convert the model to its JSON encodeable array form. * - * @return void + * @return array */ public function toArray() { @@ -884,7 +884,7 @@ public function newDn($dn = null) /** * Get the model's object GUID key. * - * @return void + * @return string */ public function getObjectGuidKey() { diff --git a/src/Models/Relations/OneToMany.php b/src/Models/Relations/OneToMany.php index d0a407cc..6d14c857 100644 --- a/src/Models/Relations/OneToMany.php +++ b/src/Models/Relations/OneToMany.php @@ -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 */ diff --git a/src/Query/Collection.php b/src/Query/Collection.php index a02146dc..036affa2 100644 --- a/src/Query/Collection.php +++ b/src/Query/Collection.php @@ -13,6 +13,7 @@ class Collection extends BaseCollection protected function valueRetriever($value) { if ($this->useAsCallable($value)) { + /** @var callable $value */ return $value; } diff --git a/src/Query/Events/QueryExecuted.php b/src/Query/Events/QueryExecuted.php index f13ddeb3..4f17ea2a 100644 --- a/src/Query/Events/QueryExecuted.php +++ b/src/Query/Events/QueryExecuted.php @@ -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; diff --git a/src/Query/ObjectNotFoundException.php b/src/Query/ObjectNotFoundException.php index b2dec28c..c22563cf 100644 --- a/src/Query/ObjectNotFoundException.php +++ b/src/Query/ObjectNotFoundException.php @@ -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 */ diff --git a/src/Query/Pagination/AbstractPaginator.php b/src/Query/Pagination/AbstractPaginator.php index 3dfd3f12..0c6ffb19 100644 --- a/src/Query/Pagination/AbstractPaginator.php +++ b/src/Query/Pagination/AbstractPaginator.php @@ -106,7 +106,7 @@ abstract protected function applyServerControls(LdapInterface $ldap); * * @param LdapInterface $ldap * - * @return mixed + * @return void */ abstract protected function resetServerControls(LdapInterface $ldap); diff --git a/src/Query/Pagination/Paginator.php b/src/Query/Pagination/Paginator.php index 9ab6e670..45337d5e 100644 --- a/src/Query/Pagination/Paginator.php +++ b/src/Query/Pagination/Paginator.php @@ -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,