• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / auth / 16143707770

03 Jul 2025 11:49AM UTC coverage: 59.727% (-0.1%) from 59.854%
16143707770

push

github

daycry
Merge branch 'development' of https://github.com/daycry/auth into development

13 of 21 new or added lines in 4 files covered. (61.9%)

32 existing lines in 4 files now uncovered.

1879 of 3146 relevant lines covered (59.73%)

22.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.5
/src/Models/RememberModel.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Models;
15

16
use CodeIgniter\I18n\Time;
17
use DateTime;
18
use Daycry\Auth\Entities\User;
19
use Faker\Generator;
20
use stdClass;
21

22
class RememberModel extends BaseModel
23
{
24
    protected $primaryKey     = 'id';
25
    protected $returnType     = 'object';
26
    protected $useSoftDeletes = false;
27
    protected $allowedFields  = [
28
        'selector',
29
        'hashedValidator',
30
        'user_id',
31
        'expires',
32
    ];
33
    protected $useTimestamps = true;
34
    protected $createdField  = 'created_at';
35
    protected $updatedField  = 'updated_at';
36
    protected $deletedField  = 'deleted_at';
37

38
    protected function initialize(): void
39
    {
40
        parent::initialize();
38✔
41

42
        $this->table = $this->tables['remember_tokens'];
38✔
43
    }
44

45
    public function fake(Generator &$faker): stdClass
46
    {
47
        return (object) [
1✔
48
            'user_id'         => 1,
1✔
49
            'selector'        => 'selector',
1✔
50
            'hashedValidator' => 'validator',
1✔
51
            'expires'         => Time::parse('+1 day')->format('Y-m-d H:i:s'),
1✔
52
        ];
1✔
53
    }
54

55
    /**
56
     * Stores a remember-me token for the user.
57
     */
58
    public function rememberUser(User $user, string $selector, string $hashedValidator, string $expires): void
59
    {
60
        $expires = new DateTime($expires);
6✔
61

62
        $return = $this->insert([
6✔
63
            'user_id'         => $user->id,
6✔
64
            'selector'        => $selector,
6✔
65
            'hashedValidator' => $hashedValidator,
6✔
66
            'expires'         => $expires->format('Y-m-d H:i:s'),
6✔
67
        ]);
6✔
68

69
        $this->checkQueryReturn($return);
6✔
70
    }
71

72
    /**
73
     * Returns the remember-me token info for a given selector.
74
     */
75
    public function getRememberToken(string $selector): ?stdClass
76
    {
77
        return $this->where('selector', $selector)->get()->getRow(); // @phpstan-ignore-line
8✔
78
    }
79

80
    /**
81
     * Updates the validator for a given selector.
82
     */
83
    public function updateRememberValidator(stdClass $token): void
84
    {
85
        $return = $this->save($token);
1✔
86

87
        $this->checkQueryReturn($return);
1✔
88
    }
89

90
    /**
91
     * Removes all persistent login tokens (remember-me) for a single user
92
     * across all devices they may have logged in with.
93
     */
94
    public function purgeRememberTokens(User $user): void
95
    {
96
        $return = $this->where(['user_id' => $user->id])->delete();
5✔
97

98
        $this->checkQueryReturn($return);
5✔
99
    }
100

101
    /**
102
     * Purges the 'auth_remember_tokens' table of any records that are past
103
     * their expiration date already.
104
     */
105
    public function purgeOldRememberTokens(): void
106
    {
UNCOV
107
        $return = $this->where('expires <=', date('Y-m-d H:i:s'))
×
UNCOV
108
            ->delete();
×
109

UNCOV
110
        $this->checkQueryReturn($return);
×
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc