Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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<string, mixed>|null.'
identifier: offsetAccess.notFound
count: 2
path: src/Auth/User.php
2 changes: 2 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,5 +9,6 @@ parameters:
level: 8
paths:
- src
reportIgnoresWithoutComments: true
reportUnmatchedIgnoredErrors: true
treatPhpDocTypesAsCertain: false
7 changes: 4 additions & 3 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Auth

/**
* Internal instance of Leaf DB
* @var Db
* @var ?Db
*/
protected $db;
protected $db = null;

/**
* All errors caught
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -949,6 +949,7 @@ public function db()
return $this->db;
}

/** @phpstan-assert Db $this->db */
Comment thread
fadrian06 marked this conversation as resolved.
protected function checkDbConnection(): void
{
if (!$this->db && function_exists('db')) {
Expand Down
17 changes: 12 additions & 5 deletions src/Auth/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*
* @since 3.0.0
* @version 1.0.0
* @property mixed $email
*/
class User
{
Expand Down Expand Up @@ -49,7 +50,9 @@ class User

/**
* All errors caught
* @var array
* @var array{
* password?: string,
* } | array<string, string>
*/
protected $errorsArray = [];
Comment thread
fadrian06 marked this conversation as resolved.

Expand Down Expand Up @@ -122,7 +125,9 @@ public function id()
* ---
* Update user data in the database
*
* @param array $userData User data
* @param array{
* email?: string,
* } | array<string, mixed> $userData User data
* @return bool
*/
public function update(array $userData): bool
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -441,7 +446,9 @@ public function setDb($db)

/**
* Get user errors
* @return array
* @return array{
* password?: string,
* } | array<string, string>
*/
Comment thread
fadrian06 marked this conversation as resolved.
public function errors()
{
Expand Down