CompositeTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compositeTraitGetChildren() 0 4 1
A __call() 0 4 1
A dispatch() 0 9 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