Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kenjis opened this issue Dec 3, 2023 · 0 comments · May be fixed by #26
Open

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

kenjis opened this issue Dec 3, 2023 · 0 comments · May be fixed by #26
Labels
bug Something isn't working

Comments

@kenjis
Copy link

kenjis commented Dec 3, 2023

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"
]
@kenjis kenjis added the bug Something isn't working label Dec 3, 2023
@paulbalandan paulbalandan linked a pull request Feb 16, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant