Passed
Push — master ( 4748af...82e71c )
by Pol
03:57
created

RSample   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A on() 0 9 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use Closure;
8
use loophp\collection\Contract\Operation;
9
10
/**
11
 * Class RSample.
12
 */
13
final class RSample implements Operation
14
{
15
    /**
16
     * @var float
17
     */
18
    private $probability;
19
20
    /**
21
     * RSample constructor.
22
     *
23
     * @param float $probability
24
     */
25 1
    public function __construct(float $probability)
26
    {
27 1
        $this->probability = $probability;
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public function on(iterable $collection): Closure
34
    {
35 1
        $probability = $this->probability;
36
37
        $callback = static function ($item) use ($probability): bool {
0 ignored issues
show
Unused Code introduced by
The parameter $item is not used and could be removed. ( Ignorable by Annotation )

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

37
        $callback = static function (/** @scrutinizer ignore-unused */ $item) use ($probability): bool {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38 1
            return (mt_rand() / mt_getrandmax()) < $probability;
39 1
        };
40
41 1
        return (new Filter($callback))->on($collection);
42
    }
43
}
44