Passed
Pull Request — master (#7)
by Nicolas
02:40 queued 01:05
created

Chunk   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A chunk() 0 15 5
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:
15
     *                       bool `preserveKeys` to prevent reindexing, default to false
16
     *                       bool `decorate` to generate chains instead of arrays, default tu true
17
     *
18
     * @return self
19
     */
20
    public function chunk(int $size, array $options = []): self
21
    {
22
        if (!empty($options['preserveKeys'])) {
23
            $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...
24
        } else {
25
            $this->array = array_chunk($this->array, $size);
26
        }
27
28
        if (empty($options['decorate']) || true === $options['decorate']) {
29
            foreach ($this->array as $index => $chunk) {
30
                $this->array[$index] = new static($chunk);
0 ignored issues
show
Unused Code introduced by
The call to Cocur\Chain\Link\Chunk::__construct() has too many arguments starting with $chunk. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
                $this->array[$index] = /** @scrutinizer ignore-call */ new static($chunk);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
31
            }
32
        }
33
34
        return $this;
35
    }
36
}
37