Conditions | 4 |
Paths | 4 |
Total Lines | 32 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 17 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
12 | 4 | public function __invoke(string $encodedSessionData): array |
|
13 | { |
||
14 | 4 | if ('' === $encodedSessionData) { |
|
15 | 1 | return []; |
|
16 | } |
||
17 | |||
18 | 3 | preg_match_all('/(^|;|\})(\w+)\|/i', $encodedSessionData, $matchesarray, PREG_OFFSET_CAPTURE); |
|
19 | |||
20 | 3 | $decodedData = []; |
|
21 | |||
22 | 3 | $lastOffset = null; |
|
23 | 3 | $currentKey = ''; |
|
24 | 3 | foreach ($matchesarray[2] as $value) { |
|
25 | 3 | $offset = $value[1]; |
|
26 | 3 | if (null !== $lastOffset) { |
|
27 | 2 | $valueText = substr($encodedSessionData, $lastOffset, $offset - $lastOffset); |
|
28 | |||
29 | /** @noinspection UnserializeExploitsInspection */ |
||
30 | 2 | $decodedData[$currentKey] = unserialize($valueText); |
|
31 | } |
||
32 | 3 | $currentKey = $value[0]; |
|
33 | |||
34 | 3 | $lastOffset = $offset + strlen($currentKey) + 1; |
|
35 | } |
||
36 | |||
37 | 3 | $valueText = substr($encodedSessionData, $lastOffset); |
|
38 | |||
39 | /** @noinspection UnserializeExploitsInspection */ |
||
40 | 3 | $decodedData[$currentKey] = unserialize($valueText); |
|
41 | |||
42 | 3 | return $decodedData; |
|
43 | } |
||
44 | } |
||
45 |