TimesInitializer::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Underscore\Initializer;
4
5
use Underscore\Collection;
6
use Underscore\Initializer;
7
use Underscore\Underscore;
8
9
class TimesInitializer extends Initializer
10
{
11
    /**
12
     * Invokes the given iteratee function n times.
13
     *
14
     * Each invocation of iteratee is called with an index argument. Produces a
15
     * Collection of the returned values.
16
     *
17
     * @param integer  $count
18
     * @param callable $function
19
     * @return Underscore
20
     */
21 1
    public function __invoke($count, $function /*, $context */)
22
    {
23
        // Context switching is possible in PHP 5.4 by using Closure::bind.
24
25 1
        $results = [];
26 1
        for ($i = 0; $i < $count; $i++) {
27 1
            $results[] = $function($i);
28
        }
29
30 1
        return new Underscore(new Collection($results));
31
    }
32
}
33