CodeIgniter / phpstan-codeigniter

CodeIgniter extensions and rules for PHPStan
https://codeigniter.com/
MIT License
15 stars 0 forks source link

bug: the type of returned array by `$model->first()` is not correct #19

Open kenjis opened 11 months ago

kenjis commented 11 months ago

PHP Version

8.1

PHPStan CodeIgniter Version

v1.4.2.70400

PHPStan Version

1.10.47

What happened?

The type of returned array by $model->select()->asArray()->first() is not correct.

Minimum Reproduction Script

https://github.com/codeigniter4/shield/blob/cecec6703d55463d6b6a34a14af58b199886a7de/src/Models/UserModel.php#L207

        if ($email !== null) {
            $data = $this->select(
                sprintf('%1$s.*, %2$s.secret as email, %2$s.secret2 as password_hash', $this->table, $this->tables['identities'])
            )
                ->join($this->tables['identities'], sprintf('%1$s.user_id = %2$s.id', $this->tables['identities'], $this->table))
                ->where($this->tables['identities'] . '.type', Session::ID_TYPE_EMAIL_PASSWORD)
                ->where(
                    'LOWER(' . $this->db->protectIdentifiers($this->tables['identities'] . '.secret') . ')',
                    strtolower($email)
                )
                ->asArray()
                ->first();

            \PHPStan\dumpType($data);
            // ...
        }
 ------ ---------------------------------------------------------------------------------------------------------- 
  Line   src/Models/UserModel.php                                                                                  
 ------ ---------------------------------------------------------------------------------------------------------- 
  219    Dumped type: array{username: string, status: string, status_message: string, active: bool, last_active:   
         string}|null 

Expected Output

Actual data:

array (11) [
    'id' => integer 1
    'username' => string (8) "newuser4"
    'status' => null
    'status_message' => null
    'active' => integer 1
    'last_active' => null
    'created_at' => string (19) "2023-12-02 23:54:50"
    'updated_at' => string (19) "2023-12-02 23:54:51"
    'deleted_at' => null
    'email' => string (17) "user4@example.com"
    'password_hash' => string (60) "$2y$12$QJRoZ.y7O6MmX2nlBpLdrukEmnlRsZbimdso5ax9w8pegKcT5dTuu"
]