Completed
Push — master ( 798ed3...31d6a2 )
by Dmitry
01:44
created

Procedure::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 0
1
<?php
2
3
namespace Tarantool\Mapper;
4
5
use Tarantool\Mapper\Plugin\Procedure as ProcedurePlugin;
6
7
abstract class Procedure
8
{
9
    private $plugin;
10
11
    public function __construct(ProcedurePlugin $plugin)
12
    {
13
        $this->plugin = $plugin;
14
    }
15
16
    abstract public function getBody() : string;
17
    abstract public function getParams() : array;
18
19
    public function getName() : string
20
    {
21
        $class = get_class($this);
22
        $name = str_replace("Procedure\\", '', $class);
23
        return strtolower(implode('_', explode('\\', $name)));
24
    }
25
26
    public function getMapping() : array
27
    {
28
        return [];
29
    }
30
31
    public function __invoke()
32
    {
33
        $raw = $this->plugin->invoke($this, func_get_args());
34
        if (!count($this->getMapping())) {
35
            return $raw;
36
        }
37
38
        $result = [];
39
        foreach ($this->getMapping() as $i => $name) {
40
            $result[$name] = $raw[$i];
41
        }
42
        return $result;
43
    }
44
}
45