GetInfoTrait::getInfoFromData()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.8666
cc 4
nc 3
nop 1
crap 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