Completed
Pull Request — master (#447)
by Alexandru
01:41
created

Helpers::redisListToArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets;
4
5
class Helpers
6
{
7
    /**
8
     * Transform the Redis' list of key after value
9
     * to key-value pairs.
10
     *
11
     * @param  array  $list
12
     * @return array
13
     */
14
    public static function redisListToArray(array $list)
15
    {
16
        // Redis lists come into a format where the keys are on even indexes
17
        // and the values are on odd indexes. This way, we know which
18
        // ones are keys and which ones are values and their get combined
19
        // later to form the key => value array.
20
        [$keys, $values] = collect($list)->partition(function ($value, $key) {
0 ignored issues
show
Bug introduced by
The variable $keys does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $values does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
21
            return $key % 2 === 0;
22
        });
23
24
        return array_combine($keys->all(), $values->all());
25
    }
26
}
27