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

GetInfoTrait   A

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 11
cts 11
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
/**
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