Completed
Pull Request — 1.x (#286)
by Alexander
02:43
created

StaticInitializationJoinpoint   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 88
ccs 0
cts 37
cp 0
rs 10
c 1
b 0
f 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A proceed() 0 7 2
A __invoke() 0 6 1
A getThis() 0 4 1
A getStaticPart() 0 4 1
A __toString() 0 7 1
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2011, 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
use Go\Core\AspectContainer;
14
use ReflectionClass;
15
16
/**
17
 * Static initialization joinpoint is invoked after class is loaded into memory
18
 */
19
class StaticInitializationJoinpoint extends AbstractJoinpoint
20
{
21
22
    /**
23
     * @var ReflectionClass
24
     */
25
    protected $reflectionClass;
26
27
    /**
28
     * Constructor for static initialization joinpoint
29
     *
30
     * @param string $className Name of the class
31
     * @param string $type Type of joinpoint
32
     * @param $advices array List of advices for this invocation
33
     *
34
     * @internal param ReflectionClass $reflectionClass Reflection of class
35
     */
36
    public function __construct($className, $type, array $advices)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        if (strpos($className, AspectContainer::AOP_PROXIED_SUFFIX)) {
39
            $originalClass = substr($className, 0, -strlen(AspectContainer::AOP_PROXIED_SUFFIX));
40
        } else {
41
            $originalClass = $className;
42
        }
43
        $this->reflectionClass = new \ReflectionClass($originalClass);
44
        parent::__construct($advices);
45
    }
46
47
    /**
48
     * Proceeds to the next interceptor in the chain.
49
     *
50
     * @return mixed see the children interfaces' proceed definition.
51
     */
52
    public function proceed()
53
    {
54
        if (isset($this->advices[$this->current])) {
55
            $currentInterceptor = $this->advices[$this->current++];
56
            $currentInterceptor->invoke($this);
57
        }
58
    }
59
60
    /**
61
     * Invokes current joinpoint with all interceptors
62
     *
63
     * @return mixed
64
     */
65
    final public function __invoke()
66
    {
67
        $this->current = 0;
68
69
        return $this->proceed();
70
    }
71
72
    /**
73
     * Returns the object that holds the current joinpoint's static
74
     * part.
75
     *
76
     * @return object|null the object (can be null if the accessible object is
77
     * static).
78
     */
79
    public function getThis()
80
    {
81
        return null;
82
    }
83
84
    /**
85
     * Returns the static part of this joinpoint.
86
     *
87
     * @return ReflectionClass
88
     */
89
    public function getStaticPart()
90
    {
91
        return $this->reflectionClass;
92
    }
93
94
    /**
95
     * Returns a friendly description of current joinpoint
96
     *
97
     * @return string
98
     */
99
    final public function __toString()
100
    {
101
        return sprintf(
102
            "staticinitialization(%s)",
103
            $this->reflectionClass->getName()
104
        );
105
    }
106
}
107