Passed
Push — master ( 337d8e...76e5f0 )
by Gabriel
02:33
created

FilterTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A only() 0 7 3
A splice() 0 7 2
1
<?php
2
3
namespace Nip\Collections\Traits;
4
5
use Nip\Utility\Arr;
6
7
/**
8
 * Trait FilterTrait
9
 * @package Nip\Collections\Traits
10
 */
11
trait FilterTrait
12
{
13
    /**
14
     * Get the items with the specified keys.
15
     *
16
     * @param  mixed  $keys
17
     * @return static
18
     */
19 1
    public function only($keys)
20
    {
21 1
        if (is_null($keys)) {
22 1
            return new static($this->items);
0 ignored issues
show
Unused Code introduced by
The call to Nip\Collections\Traits\FilterTrait::__construct() has too many arguments starting with $this->items. ( Ignorable by Annotation )

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

22
            return /** @scrutinizer ignore-call */ new static($this->items);

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...
23
        }
24 1
        $keys = is_array($keys) ? $keys : func_get_args();
25 1
        return new static(Arr::only($this->items, $keys));
26
    }
27
28
    /**
29
     * Splice a portion of the underlying collection array.
30
     *
31
     * @param int $offset
32
     * @param int|null $length
33
     * @param mixed $replacement
34
     * @return static
35
     */
36 1
    public function splice($offset, $length = null, $replacement = [])
37
    {
38 1
        if (func_num_args() === 1) {
39
            return new static(array_splice($this->items, $offset));
0 ignored issues
show
Unused Code introduced by
The call to Nip\Collections\Traits\FilterTrait::__construct() has too many arguments starting with array_splice($this->items, $offset). ( Ignorable by Annotation )

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

39
            return /** @scrutinizer ignore-call */ new static(array_splice($this->items, $offset));

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...
40
        }
41
42 1
        return new static(array_splice($this->items, $offset, $length, $replacement));
43
    }
44
}