Traitor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 27
rs 10
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A traitor() 0 20 6
A traitorPattern() 0 3 1
1
<?php
2
3
namespace HexMakina\Traitor;
4
5
trait Traitor
6
{
7
    public function traitor($method_name)
8
    {
9
        $ret = [];
10
11
        $regex = sprintf($this->traitorPattern(), $method_name);
12
13
        $traits = (new \ReflectionClass($this))->getTraitNames();
14
        foreach ($traits as $trait_name) {
15
            $trait_methods = (new \ReflectionClass($trait_name))->getMethods();
16
            foreach ($trait_methods as $method) {
17
                if (preg_match($regex, $method->name, $match) === 1) {
18
                    $callable = current($match);
19
                    $res = $this->$callable();
20
                    if(is_array($res) && !empty($res))
21
                        $ret[$trait_name . '::' . $method->name] = $res;
22
                }
23
            }
24
        }
25
26
        return $ret;
27
    }
28
29
    public function traitorPattern()
30
    {
31
        return '/.+Traitor_%s$/';
32
    }
33
}
34