TimesInitializer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 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