Passed
Branch master (a01aa4)
by Mike
03:32
created

ChainedInflector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 29
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A inflect() 0 10 3
1
<?php
2
3
namespace MGDigital\BusQue\Tactician;
4
5
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector;
6
7
class ChainedInflector implements MethodNameInflector
8
{
9
10
    /**
11
     * @var MethodNameInflector[]
12
     */
13
    private $inflectors = [];
14
15
    /**
16
     * @param MethodNameInflector[] $inflectors
17
     */
18
    public function __construct(array $inflectors)
19
    {
20
        array_walk($inflectors, function (MethodNameInflector $inflector) {
21
            $this->inflectors[] = $inflector;
22
        });
23
    }
24
25
    public function inflect($command, $handler)
26
    {
27
        foreach ($this->inflectors as $inflector) {
28
            $methodName = $inflector->inflect($command, $handler);
29
            if (is_callable([$handler, $methodName])) {
30
                return $methodName;
31
            }
32
        }
33
        throw new \RuntimeException('None of the inflectors could guess the handler method name.');
34
    }
35
}
36