Completed
Push — master ( 6c1856...1699d4 )
by Arnold
03:39
created

GetInfoTrait::getInfoFromData()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
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 11
cts 11
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
/**
8
 * Get to get info from data.
9
 */
10
trait GetInfoTrait
11
{
12
    /**
13
     * @param array<string,mixed>|\ArrayAccess<string,mixed> $data
14
     * @return array{user:mixed,context:mixed,checksum:string|null,timestamp:\DateTimeInterface|null}
15
     */
16 9
    private function getInfoFromData($data): array
17
    {
18 9
        $timestamp = $data['timestamp'] ?? null;
19
20
        try {
21 9
            if ($timestamp !== null && !($timestamp instanceof \DateTimeInterface)) {
22 9
                $timestamp = new \DateTimeImmutable('@' . $data['timestamp']);
23
            }
24 1
        } catch (\Throwable $exception) {
25 1
            trigger_error($exception->getMessage(), E_USER_WARNING);
26 1
            $timestamp = null;
27
        }
28
29
        return [
30 9
            'user' => $data['user'] ?? null,
31 9
            'context' => $data['context'] ?? null,
32 9
            'checksum' => $data['checksum'] ?? null,
33 9
            'timestamp' => $timestamp,
34
        ];
35
    }
36
}
37