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

daycry / auth / 25518434194

07 May 2026 07:49PM UTC coverage: 58.608% (-6.4%) from 64.989%
25518434194

push

github

web-flow
Merge pull request #47 from daycry/development

Implement security enhancements and new account features

277 of 1030 new or added lines in 55 files covered. (26.89%)

11 existing lines in 6 files now uncovered.

3544 of 6047 relevant lines covered (58.61%)

47.97 hits per line

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

17.65
/src/Models/AuditLogModel.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 Daycry\Auth\Entities\AuditLog;
18

19
/**
20
 * Stores granular security/account events distinct from {@see LogModel}
21
 * (request-level activity) and {@see LoginModel} (login attempts).
22
 *
23
 * Use via the {@see \Daycry\Auth\Services\AuditLogger} service rather than
24
 * inserting rows directly — the service handles JSON encoding, IP/UA
25
 * resolution, and timestamp formatting.
26
 */
27
class AuditLogModel extends BaseModel
28
{
29
    protected $primaryKey     = 'id';
30
    protected $returnType     = AuditLog::class;
31
    protected $useSoftDeletes = false;
32
    protected $allowedFields  = [
33
        'user_id',
34
        'actor_id',
35
        'event_type',
36
        'ip_address',
37
        'user_agent',
38
        'metadata',
39
        'created_at',
40
    ];
41
    protected $useTimestamps = false; // We set created_at explicitly.
42

43
    protected function initialize(): void
50✔
44
    {
45
        parent::initialize();
50✔
46

47
        $this->table = $this->tables['audit_logs'] ?? 'auth_audit_logs';
50✔
48
    }
49

50
    /**
51
     * Returns the most recent events for a user (newest first).
52
     *
53
     * @return list<AuditLog>
54
     */
NEW
55
    public function recentForUser(int $userId, int $limit = 50): array
×
56
    {
NEW
57
        return $this
×
NEW
58
            ->where('user_id', $userId)
×
NEW
59
            ->orderBy('created_at', 'DESC')
×
NEW
60
            ->limit($limit)
×
NEW
61
            ->find();
×
62
    }
63

64
    /**
65
     * Returns events filtered by type and time window.
66
     *
67
     * @return list<AuditLog>
68
     */
NEW
69
    public function recentByType(string $eventType, ?Time $since = null, int $limit = 100): array
×
70
    {
NEW
71
        $builder = $this
×
NEW
72
            ->where('event_type', $eventType)
×
NEW
73
            ->orderBy('created_at', 'DESC')
×
NEW
74
            ->limit($limit);
×
75

NEW
76
        if ($since !== null) {
×
NEW
77
            $builder = $builder->where('created_at >=', $since->toDateTimeString());
×
78
        }
79

NEW
80
        return $builder->find();
×
81
    }
82
}
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