Completed
Push — master ( e85a68...b6ead1 )
by Jesse
03:13
created

Executing::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stratadox\ImmutableCollection;
6
7
use Closure;
8
use Stratadox\Collection\Executable;
9
10
/**
11
 * Behaviour to execute a closure on each item in the collection.
12
 *
13
 * Provides access to execution behaviour in the form of a method that
14
 * executes an anonymous function on each item in the collection.
15
 *
16
 * @package Stratadox\Collection
17
 * @author Stratadox
18
 */
19
trait Executing
20
{
21
    /**
22
     * @see Executable::execute()
23
     * @param Closure $function
24
     */
25
    public function execute(Closure $function) : void
26
    {
27
        foreach ($this as $position => $item) {
28
            if (is_object($item)) {
29
                $function->call($item, $position, $item);
30
            } else {
31
                $function($position, $item);
32
            }
33
        }
34
    }
35
}
36