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

Chunk::chunk()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 0
cts 5
cp 0
crap 6
rs 10
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