Passed
Pull Request — master (#7)
by Nicolas
01:55
created

Chunk   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 5
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A chunk() 0 9 2
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
/**
6
 * Chunk.
7
 *
8
 * @author    Nicolas Reynis
9
 */
10
trait Chunk
11
{
12
    /**
13
     * @param int $size
14
     * @param array $options options, including `preserveKeys` to prevent reindexing
15
     *
16
     * @return self
17
     */
18
    public function chunk(int $size, array $options = []): self
19
    {
20
        if (!empty($options['preserveKeys'])) {
21
            $this->array = array_chunk($this->array, $size, $options['preserveKeys']);
0 ignored issues
show
Bug Best Practice introduced by
The property array does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
        } else {
23
            $this->array = array_chunk($this->array, $size);
24
        }
25
26
        return $this;
27
    }
28
}
29