FindAccessor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 3
1
<?php
2
3
namespace Underscore\Accessor;
4
5
use Underscore\Accessor;
6
use Underscore\Collection;
7
8
class FindAccessor extends Accessor
9
{
10
    /**
11
     * Iterates over elements of a collection, returning the first element that the callback returns truey for.
12
     *
13
     * Returns mixed
14
     *
15
     * @param Collection $collection
16
     * @param callable   $iterator
17
     * @return Collection
18
     */
19 4
    public function __invoke($collection, $iterator)
20
    {
21 4
        $collection = clone $collection;
22
23 4
        $found = false;
24 4
        foreach ($collection as $k => $v) {
25 4
            if (call_user_func($iterator, $v, $k, $collection)) {
26 4
                $found = true;
27 4
                break;
28
            }
29
        }
30
31 4
        return $found;
32
    }
33
}
34