Completed
Pull Request — master (#463)
by Alexander
30:17 queued 05:15
created

StaticInitializationJoinpoint   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 1
dl 0
loc 86
ccs 16
cts 24
cp 0.6667
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * Go! AOP framework
6
 *
7
 * @copyright Copyright 2011, Lisachenko Alexander <[email protected]>
8
 *
9
 * This source file is subject to the license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Go\Aop\Framework;
14
15
use Go\Aop\Intercept\ClassJoinpoint;
16
use Go\Core\AspectContainer;
17
use ReflectionClass;
18
19
use function strlen;
20
21
/**
22
 * Static initialization joinpoint is invoked after class is loaded into memory
23
 */
24
class StaticInitializationJoinpoint extends AbstractJoinpoint implements ClassJoinpoint
25
{
26
27
    protected ReflectionClass $reflectionClass;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
28
29
    /**
30
     * Constructor for the class static initialization joinpoint
31
     *
32
     * @param array $advices List of advices for this invocation
33
     */
34 1
    public function __construct(array $advices, string $className)
35
    {
36 1
        $originalClass = $className;
37 1
        if (strpos($originalClass, AspectContainer::AOP_PROXIED_SUFFIX)) {
38 1
            $originalClass = substr($originalClass, 0, -strlen(AspectContainer::AOP_PROXIED_SUFFIX));
39
        }
40 1
        $this->reflectionClass = new ReflectionClass($originalClass);
41 1
        parent::__construct($advices);
42 1
    }
43
44
    /**
45
     * Proceeds to the next interceptor in the chain.
46
     *
47
     * @return void Covariant, as static initializtion could not return anything
48
     */
49 1
    public function proceed(): void
50
    {
51 1
        if (isset($this->advices[$this->current])) {
52 1
            $currentInterceptor = $this->advices[$this->current++];
53 1
            $currentInterceptor->invoke($this);
54
        }
55 1
    }
56
57
    /**
58
     * Invokes current joinpoint with all interceptors
59
     */
60 1
    final public function __invoke(): void
61
    {
62 1
        $this->current = 0;
63 1
        $this->proceed();
64 1
    }
65
66
    /**
67
     * Returns the object for which current joinpoint is invoked
68
     *
69
     * @return object|null Instance of object or null for static call/unavailable context
70
     */
71
    public function getThis(): ?object
72
    {
73
        return null;
74
    }
75
76
    /**
77
     * Checks if the current joinpoint is dynamic or static
78
     *
79
     * Dynamic joinpoint contains a reference to an object that can be received via getThis() method call
80
     *
81
     * @see ClassJoinpoint::getThis()
82
     */
83
    public function isDynamic(): bool
84
    {
85
        return false;
86
    }
87
88
    /**
89
     * Returns the static scope name (class name) of this joinpoint.
90
     */
91
    public function getScope(): string
92
    {
93
        return $this->reflectionClass->getName();
94
    }
95
96
    /**
97
     * Returns a friendly description of current joinpoint
98
     */
99
    final public function __toString(): string
100
    {
101
        return sprintf(
102
            'staticinitialization(%s)',
103
            $this->getScope()
104
        );
105
    }
106
}
107