Passed
Push — main ( 21a5e3...5e30dc )
by Sammy
01:44
created

Traitor::traitor()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 16
rs 9.9332
1
<?php
2
3
namespace HexMakina\Traitor;
4
5
trait Traitor
6
{
7
    public function traitor($method_name)
8
    {
9
        $regex = sprintf('/.+Traitor_%s$/', $method_name);
10
        $errors = [];
11
        $traits = (new \ReflectionClass($this))->getTraitNames();
12
13
        foreach ($traits as $trait_name) {
14
            $trait_methods = (new \ReflectionClass($trait_name))->getMethods();
15
            foreach ($trait_methods as $method) {
16
                if (preg_match($regex, $method->name, $match) === 1) {
17
                    $callable = current($match);
18
                    $errors ["$trait_name::" . $method->name] = $this->$callable();
19
                }
20
            }
21
        }
22
        return $errors;
23
    }
24
}
25