diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e69de29..93867b4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -0,0 +1,19 @@ +parameters: + ignoreErrors: + - + rawMessage: 'Method Leaf\Auth::db() should return Leaf\Db but returns Leaf\Db|null.' + identifier: return.type + count: 1 + path: src/Auth.php + + - + rawMessage: 'Parameter #1 $db of method Leaf\Auth\User::setDb() expects Leaf\Db, Leaf\Db|null given.' + identifier: argument.type + count: 1 + path: src/Auth.php + + - + rawMessage: 'Offset ''status'' might not exist on array|null.' + identifier: offsetAccess.notFound + count: 2 + path: src/Auth/User.php diff --git a/phpstan.dist.neon b/phpstan.dist.neon index 059070d..6755c94 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/fadrian06/phpstan/refs/heads/add-schema/schema.json includes: - vendor/phpstan/phpstan/conf/bleedingEdge.neon - phpstan-baseline.neon @@ -8,5 +9,6 @@ parameters: level: 8 paths: - src + reportIgnoresWithoutComments: true reportUnmatchedIgnoredErrors: true treatPhpDocTypesAsCertain: false diff --git a/src/Auth.php b/src/Auth.php index be6ecb8..79f2f83 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -34,9 +34,9 @@ class Auth /** * Internal instance of Leaf DB - * @var Db + * @var ?Db */ - protected $db; + protected $db = null; /** * All errors caught @@ -171,7 +171,7 @@ public function autoConnect(array $pdoOptions = []) * Pass in db connection instance directly * * @param PDO $connection A connection instance of your db - * @return $this; + * @return $this */ public function dbConnection(PDO $connection) { @@ -949,6 +949,7 @@ public function db() return $this->db; } + /** @phpstan-assert Db $this->db */ protected function checkDbConnection(): void { if (!$this->db && function_exists('db')) { diff --git a/src/Auth/User.php b/src/Auth/User.php index f8a31de..c1d54ef 100644 --- a/src/Auth/User.php +++ b/src/Auth/User.php @@ -18,6 +18,7 @@ * * @since 3.0.0 * @version 1.0.0 + * @property mixed $email */ class User { @@ -49,7 +50,9 @@ class User /** * All errors caught - * @var array + * @var array{ + * password?: string, + * } | array */ protected $errorsArray = []; @@ -122,7 +125,9 @@ public function id() * --- * Update user data in the database * - * @param array $userData User data + * @param array{ + * email?: string, + * } | array $userData User data * @return bool */ public function update(array $userData): bool @@ -293,11 +298,11 @@ public function getAuthInfo(): object 'refreshToken' => $this->tokens['refresh'] ?? null, ]; - if (count($this->roles ?? [])) { + if (count($this->roles)) { $dataToReturn->roles = $this->roles; } - if (count($this->permissions ?? [])) { + if (count($this->permissions)) { $dataToReturn->permissions = $this->permissions; } @@ -441,7 +446,9 @@ public function setDb($db) /** * Get user errors - * @return array + * @return array{ + * password?: string, + * } | array */ public function errors() {