AllAccessor::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Underscore\Accessor;
4
5
use Underscore\Accessor;
6
use Underscore\Collection;
7
8
class AllAccessor extends Accessor
9
{
10
    /**
11
     * Checks if the $iterator returns a truey value for ALL element of a collection.
12
     *
13
     * Returns boolean
14
     *
15
     * @param Collection $collection
16
     * @param callable   $iterator
17
     * @return Collection
18
     */
19
    public function __invoke($collection, $iterator)
20
    {
21 1
        $iterator = function ($accumulator, $item) use ($iterator) {
22 1
            $accumulator = $accumulator && $iterator($item);
23
24 1
            return $accumulator;
25 1
        };
26
27 1
        $reduce = new ReduceAccessor();
28
29 1
        return $reduce($collection, $iterator, true);
30
    }
31
}
32