| Total Complexity | 4 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 11 | trait CallableMethodTrait |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var Closure|null |
||
| 15 | */ |
||
| 16 | protected $methodsCallback = null; |
||
| 17 | |||
| 18 | public function addMethodCall(string $method, array $parameters = []) |
||
| 19 | { |
||
| 20 | $current = $this->getMethodCall(); |
||
| 21 | $newCallback = |
||
| 22 | function ($instance, ContainerInterface $container) use ($current, $method, $parameters) { |
||
| 23 | $_parameters = (new ArrayDefinition($parameters))->getConcrete($container); |
||
| 24 | $current($instance, $container); |
||
| 25 | if (!is_object($instance) || !method_exists($instance, $method)) { |
||
| 26 | throw DefinitionException::invalidMethodCall($this, $instance, $method); |
||
|
|
|||
| 27 | } |
||
| 28 | call_user_func_array([$instance, $method], $_parameters); |
||
| 29 | }; |
||
| 30 | $this->methodsCallback = $newCallback; |
||
| 31 | return $this; |
||
| 32 | } |
||
| 33 | |||
| 34 | public function getMethodCall(): Closure |
||
| 37 | } ; |
||
| 38 | } |
||
| 40 |