Executing::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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