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

ChainedInflector::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 3
nc 1
nop 1
crap 2
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