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

Executing   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 10
c 0
b 0
f 0
wmc 3

1 Method

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