Skip to content

Commit cd082a9

Browse files
committed
up: format some codes for aop
1 parent e1f68c0 commit cd082a9

5 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/aop/src/Annotation/Mapping/Aspect.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\Common\Annotations\Annotation\Attribute;
66
use Doctrine\Common\Annotations\Annotation\Attributes;
77
use Doctrine\Common\Annotations\Annotation\Target;
8+
use const PHP_INT_MAX;
89

910
/**
1011
* Class Aspect
@@ -49,4 +50,4 @@ public function getOrder(): int
4950
{
5051
return $this->order;
5152
}
52-
}
53+
}

src/aop/src/AspectHandler.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,15 @@ public function invokeTarget(array $params = [])
134134
$before = $this->aspect['before'] ?? [];
135135

136136
// Invoke before advice
137-
if (!empty($before)) {
137+
if ($before) {
138138
$this->invokeAdvice($before);
139139
}
140140

141141
// Invoke next aspect
142-
if (!empty($this->aspects)) {
143-
$nextAspect = $this->nextHandler();
144-
$result = $nextAspect->invokeAspect();
142+
if ($this->aspects) {
143+
$nextAspect = $this->nextHandler();
144+
$result = $nextAspect->invokeAspect();
145+
145146
$this->throwable = $nextAspect->throwable;
146147

147148
return $result;

src/aop/src/Ast/Visitor/ProxyVisitor.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Swoft\Stdlib\Helper\Str;
1212
use function array_unshift;
1313
use function sprintf;
14+
use function strpos;
1415

1516
/**
1617
* Class ProxyVisitor
@@ -32,21 +33,21 @@ class ProxyVisitor extends Visitor
3233
private $namespace = '';
3334

3435
/**
35-
* New class name
36+
* New class name. it's random string. eg: '5e8455cdd6887'
3637
*
3738
* @var string
3839
*/
3940
private $proxyId;
4041

4142
/**
42-
* Origin class name
43+
* Origin class name. eg: 'SameNamespace\\SomeClass'
4344
*
4445
* @var string
4546
*/
4647
private $originalClassName = '';
4748

4849
/**
49-
* Proxy class name without namespace
50+
* Proxy class name without namespace. eg: 'SomeClass_PROXY_5e8455cdd6887'
5051
*
5152
* @var string
5253
*/
@@ -68,7 +69,8 @@ class ProxyVisitor extends Visitor
6869
public function __construct(string $proxyId = '', string $aopClassName = AopTrait::class)
6970
{
7071
$this->aopClassName = $aopClassName;
71-
$this->proxyId = $proxyId ?: Str::getUniqid();
72+
73+
$this->proxyId = $proxyId ?: Str::getUniqid();
7274
}
7375

7476
/**
@@ -82,7 +84,6 @@ public function enterNode(Node $node)
8284
{
8385
// Namespace for proxy class name
8486
if ($node instanceof Node\Stmt\Namespace_) {
85-
8687
$this->namespace = $node->name->toString();
8788
return null;
8889
}
@@ -116,7 +117,6 @@ public function leaveNode(Node $node)
116117

117118
// Parse new class node
118119
if ($node instanceof Node\Stmt\Class_) {
119-
120120
// Fix such as '\Xxxx' class bug
121121
$extendClass = $this->originalClassName;
122122
if (strpos($extendClass, '\\') !== 0) {
@@ -181,7 +181,7 @@ private function proxyMethod(ClassMethod $node): ClassMethod
181181
{
182182
$methodName = $node->name->toString();
183183

184-
$params = [];
184+
$params = []; // TODO ??
185185
foreach ($node->params as $key => $param) {
186186
$params[] = $param;
187187
}

src/aop/src/Concern/AopTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ trait AopTrait
2424
*
2525
* @return mixed
2626
* @throws Throwable
27+
* @noinspection MagicMethodsValidityInspection
2728
*/
2829
public function __proxyCall(string $className, string $methodName, array $args)
2930
{
@@ -53,6 +54,7 @@ public function __proxyCall(string $className, string $methodName, array $args)
5354
* @param array $args
5455
*
5556
* @return mixed
57+
* @noinspection MagicMethodsValidityInspection
5658
*/
5759
public function __invokeTarget(string $methodName, array $args)
5860
{

src/aop/src/Proxy.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Swoft\Aop\Ast\Visitor\ProxyVisitor;
66
use Swoft\Proxy\Exception\ProxyException;
77
use Swoft\Proxy\Proxy as BaseProxy;
8+
use function explode;
9+
use function strpos;
810

911
/**
1012
* Class Proxy
@@ -28,7 +30,7 @@ public static function newClassName(string $className): string
2830
return $className;
2931
}
3032

31-
// Ignore aop proxy
33+
// Is RPC proxy
3234
if (strpos($className, '_IGNORE_') !== false) {
3335
return $className;
3436
}
@@ -46,7 +48,7 @@ public static function newClassName(string $className): string
4648
*/
4749
public static function getClassName(string $proxyClassName): string
4850
{
49-
list($className) = explode('_', $proxyClassName);
51+
[$className] = explode('_', $proxyClassName);
5052
return $className;
5153
}
5254

@@ -59,8 +61,8 @@ public static function getClassName(string $proxyClassName): string
5961
*/
6062
public static function getOriginalClassName(string $proxyClassName): string
6163
{
62-
$proxys = explode(ProxyVisitor::PROXY, $proxyClassName);
64+
$proxies = explode(ProxyVisitor::PROXY, $proxyClassName);
6365

64-
return $proxys[0];
66+
return $proxies[0];
6567
}
6668
}

0 commit comments

Comments
 (0)