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

daycry / auth / 23386290410

21 Mar 2026 06:48PM UTC coverage: 64.989% (+1.2%) from 63.76%
23386290410

push

github

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

v5.0.0

302 of 465 new or added lines in 26 files covered. (64.95%)

19 existing lines in 3 files now uncovered.

3306 of 5087 relevant lines covered (64.99%)

47.04 hits per line

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

57.14
/src/Authentication/Services/DeviceSessionRecorder.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\Authentication\Services;
15

16
use CodeIgniter\HTTP\IncomingRequest;
17
use Daycry\Auth\Entities\User;
18
use Daycry\Auth\Models\DeviceSessionModel;
19

20
/**
21
 * Handles creation and termination of device session records.
22
 *
23
 * Extracted from Session authenticator to isolate device-tracking
24
 * concerns from the core authentication flow.
25
 */
26
class DeviceSessionRecorder
27
{
28
    /**
29
     * Creates a device session record for the given user.
30
     *
31
     * Silently returns if there is no active PHP session (e.g. in testing).
32
     */
33
    public function recordSession(User $user, string $ipAddress): void
34✔
34
    {
35
        $sessionId = session_id();
34✔
36

37
        // No active session (e.g. testing environment without a real session)
38
        if ($sessionId === '' || $sessionId === false) {
34✔
39
            return;
34✔
40
        }
41

42
        /** @var DeviceSessionModel $deviceSessionModel */
NEW
43
        $deviceSessionModel = model(DeviceSessionModel::class);
×
44

45
        /** @var IncomingRequest $incomingRequest */
NEW
46
        $incomingRequest = service('request');
×
NEW
47
        $userAgent       = (string) $incomingRequest->getUserAgent();
×
48

NEW
49
        $deviceSessionModel->createSession($user, $sessionId, $ipAddress, $userAgent !== '' ? $userAgent : null);
×
50
    }
51

52
    /**
53
     * Terminates the current device session.
54
     */
55
    public function terminateCurrentSession(): void
4✔
56
    {
57
        $sessionId = session_id();
4✔
58

59
        if ($sessionId === '' || $sessionId === false) {
4✔
60
            return;
4✔
61
        }
62

63
        /** @var DeviceSessionModel $deviceSessionModel */
NEW
64
        $deviceSessionModel = model(DeviceSessionModel::class);
×
NEW
65
        $deviceSessionModel->terminateSession($sessionId);
×
66
    }
67
}
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