Completed
Pull Request — 1.x (#301)
by
unknown
04:37
created

DynamicClosureSplatMethodInvocation::proceed()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 0
cts 16
cp 0
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 11
nc 5
nop 0
crap 20
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Aop\Framework;
12
13
class DynamicClosureSplatMethodInvocation extends DynamicClosureMethodInvocation
14
{
15
    /**
16
     * Invokes original method and return result from it
17
     *
18
     * @return mixed
19
     */
20
    public function proceed()
21
    {
22
        if (isset($this->advices[$this->current])) {
23
            /** @var $currentInterceptor \Go\Aop\Intercept\Interceptor */
24
            $currentInterceptor = $this->advices[$this->current++];
25
26
            return $currentInterceptor->invoke($this);
27
        }
28
29
        // Fill the closure only once if it's empty
30
        if (!$this->closureToCall) {
31
            $this->closureToCall = $this->reflectionMethod->getClosure($this->instance);
32
        }
33
34
        // Rebind the closure if instance was changed since last time
35
        if ($this->previousInstance !== $this->instance) {
36
            $this->closureToCall    = $this->closureToCall->bindTo($this->instance, $this->reflectionMethod->class);
37
            $this->previousInstance = $this->instance;
38
        }
39
40
        $closureToCall = $this->closureToCall;
41
42
        return $closureToCall(...$this->arguments);
43
    }
44
}
45