CompositeTrait::dispatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6667
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Tacone\Bees\Base;
4
5
trait CompositeTrait
6
{
7
    /**
8
     * Override this function to return an associative
9
     * array with all the children.
10
     *
11
     * The keys will be the same used for the composite
12
     * method calls.
13
     */
14
    protected function compositeTraitGetChildren()
15
    {
16
        throw new \LogicException('Override this method');
17
    }
18
19
    public function __call($method, $arguments)
20
    {
21
        return $this->dispatch($method, $arguments);
22
    }
23
    protected function dispatch($method, $arguments = [])
24
    {
25
        $result = [];
26
        foreach ($this->compositeTraitGetChildren() as $key => $child) {
27
            $result[$key] = call_user_func_array([$child, $method], $arguments);
28
        }
29
30
        return $result;
31
    }
32
}
33