ActiveSession::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 6
dl 0
loc 12
rs 10
1
<?php
2
3
namespace App\Security\Session;
4
5
use DateTimeImmutable;
6
7
class ActiveSession {
8
9
    public readonly array $browserInfo;
10
11
    public function __construct(public readonly int $userId, public readonly mixed $sessionId, public readonly ?string $userAgent,
12
                                public readonly DateTimeImmutable $startedAt, public readonly ?string $ipAddress, public readonly bool $isCurrentSession) {
13
        if($this->userAgent !== null) {
14
            $info = @get_browser($this->userAgent, true);
15
16
            if($info === false) {
17
                $this->browserInfo = [ ];
0 ignored issues
show
Bug introduced by
The property browserInfo is declared read-only in App\Security\Session\ActiveSession.
Loading history...
18
            } else {
19
                $this->browserInfo = $info;
20
            }
21
        } else {
22
            $this->browserInfo = [ ];
23
        }
24
    }
25
}