Completed
Push — master ( 83c33c...a2b142 )
by Florian
14s
created

Find::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Cocur\Chain\Link;
4
5
use Cocur\Chain\Chain;
6
7
/**
8
 * Find
9
 *
10
 * @package   Cocur\Chain\Link
11
 * @author    Christoph Rosse
12
 * @copyright 2017 Christoph Rosse
13
 */
14
trait Find
15
{
16
    /**
17
     * Find an element by a comparison callback.
18
     *
19
     * @param callable $callback
20
     *
21
     * @return Chain
22
     */
23 2
    public function find(callable $callback)
24
    {
25 2
        $result = array_filter($this->array, $callback);
0 ignored issues
show
Bug introduced by
The property array does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
27 2
        return empty($result) ? false : current($result);
28
    }
29
}
30