GetInfoTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getInfoFromData() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jasny\Auth\Session;
6
7
use ArrayAccess;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10
use Throwable;
11
12
/**
13
 * Get to get info from data.
14
 */
15
trait GetInfoTrait
16
{
17
    /**
18
     * @param ArrayAccess<string,mixed>|array<string,mixed> $data
19
     * @return array{user:mixed,context:mixed,checksum:string|null,timestamp:DateTimeInterface|null}
20
     */
21 9
    private function getInfoFromData(array|ArrayAccess $data): array
22
    {
23 9
        $timestamp = $data['timestamp'] ?? null;
24
25
        try {
26 9
            if ($timestamp !== null && !($timestamp instanceof DateTimeInterface)) {
27 9
                $timestamp = new DateTimeImmutable('@' . $data['timestamp']);
28
            }
29 1
        } catch (Throwable $exception) {
30 1
            trigger_error($exception->getMessage(), E_USER_WARNING);
31 1
            $timestamp = null;
32
        }
33
34 9
        return [
35 9
            'user' => $data['user'] ?? null,
36 9
            'context' => $data['context'] ?? null,
37 9
            'checksum' => $data['checksum'] ?? null,
38 9
            'timestamp' => $timestamp,
39 9
        ];
40
    }
41
}
42