From df03fd81b2f3f47c3ac32b42c2cd6373d93ad809 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 03:50:41 +0900 Subject: [PATCH 01/13] update AOP template --- template/AopTemplate.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/template/AopTemplate.php b/template/AopTemplate.php index 241ef10b..e7c25791 100644 --- a/template/AopTemplate.php +++ b/template/AopTemplate.php @@ -9,6 +9,7 @@ * @see http://stackoverflow.com/questions/1796100/what-is-faster-many-ifs-or-else-if * @see http://stackoverflow.com/questions/2401478/why-is-faster-than-in-php */ + class AopTemplate extends \Ray\Aop\FakeMock implements Ray\Aop\WeavedInterface { /** @@ -17,6 +18,7 @@ class AopTemplate extends \Ray\Aop\FakeMock implements Ray\Aop\WeavedInterface * [$methodName => [$interceptorA[]][] */ public $bindings; + /** * @var bool */ @@ -27,27 +29,20 @@ class AopTemplate extends \Ray\Aop\FakeMock implements Ray\Aop\WeavedInterface * * @param mixed $a */ - public function returnSame($a) + public function templateMethod($a) { - if (isset($this->bindings[__FUNCTION__]) === false) { - return call_user_func_array('parent::' . __FUNCTION__, func_get_args()); - } - if ($this->isIntercepting === false) { $this->isIntercepting = true; + // call original method return call_user_func_array('parent::' . __FUNCTION__, func_get_args()); } $this->isIntercepting = false; - $invocationResult = (new \Ray\Aop\ReflectiveMethodInvocation( - $this, - new \ReflectionMethod($this, __FUNCTION__), - new \Ray\Aop\Arguments(func_get_args()), - $this->bindings[__FUNCTION__] - ))->proceed(); + // invoke interceptor + $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, new \ReflectionMethod($this, __FUNCTION__), new \Ray\Aop\Arguments(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); $this->isIntercepting = true; - return $invocationResult; + return $result; } } From 33957e20c5f5212be1cbccc0d010e4073cc22162 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:08:37 +0900 Subject: [PATCH 02/13] pass method string to ReflectionMethod constructor --- src/ReflectiveMethodInvocation.php | 15 +++++++-------- template/AopTemplate.php | 2 +- tests/ReflectiveMethodInvocationTest.php | 6 +++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index d2d7be43..e9f2918a 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -21,7 +21,7 @@ final class ReflectiveMethodInvocation implements MethodInvocation private $arguments; /** - * @var \ReflectionMethod + * @var string */ private $method; @@ -32,13 +32,13 @@ final class ReflectiveMethodInvocation implements MethodInvocation /** * @param object $object - * @param \ReflectionMethod $method + * @param string $method * @param Arguments $arguments * @param MethodInterceptor[] $interceptors */ public function __construct( $object, - \ReflectionMethod $method, + string $method, Arguments $arguments, array $interceptors = [] ) { @@ -55,13 +55,13 @@ public function getMethod() : \ReflectionMethod { if ($this->object instanceof WeavedInterface) { $class = (new \ReflectionObject($this->object))->getParentClass(); - $method = new ReflectionMethod($class->name, $this->method->name); - $method->setObject($this->object, $this->method); + $method = new ReflectionMethod($class->name, $this->method); + $method->setObject($this->object, $method); return $method; } - return $this->method; + return new ReflectionMethod($this->object, $this->method); } /** @@ -93,10 +93,9 @@ public function getNamedArguments() : \ArrayObject public function proceed() { if ($this->interceptors === []) { - return $this->method->invokeArgs($this->object, $this->arguments->getArrayCopy()); + return (new ReflectionMethod($this->object, $this->method))->invokeArgs($this->object, $this->arguments->getArrayCopy()); } $interceptor = array_shift($this->interceptors); - /* @var $interceptor MethodInterceptor */ return $interceptor->invoke($this); } diff --git a/template/AopTemplate.php b/template/AopTemplate.php index e7c25791..c0008abc 100644 --- a/template/AopTemplate.php +++ b/template/AopTemplate.php @@ -40,7 +40,7 @@ public function templateMethod($a) $this->isIntercepting = false; // invoke interceptor - $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, new \ReflectionMethod($this, __FUNCTION__), new \Ray\Aop\Arguments(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); + $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, new \Ray\Aop\Arguments(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); $this->isIntercepting = true; return $result; diff --git a/tests/ReflectiveMethodInvocationTest.php b/tests/ReflectiveMethodInvocationTest.php index ef03fdfc..eab49f75 100644 --- a/tests/ReflectiveMethodInvocationTest.php +++ b/tests/ReflectiveMethodInvocationTest.php @@ -26,7 +26,7 @@ protected function setUp() { parent::setUp(); $this->fake = new FakeClass; - $this->invocation = new ReflectiveMethodInvocation($this->fake, new \ReflectionMethod($this->fake, 'add'), new Arguments([1])); + $this->invocation = new ReflectiveMethodInvocation($this->fake, 'add', new Arguments([1])); } public function testGetMethod() @@ -70,7 +70,7 @@ public function testGetThis() public function testGetParentMethod() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, new \ReflectionMethod($fake, 'add'), new Arguments([1])); + $invocation = new ReflectiveMethodInvocation($fake, 'add', new Arguments([1])); $method = $invocation->getMethod(); $this->assertSame(FakeClass::class, $method->class); $this->assertSame('add', $method->name); @@ -79,7 +79,7 @@ public function testGetParentMethod() public function testProceedMultipleInterceptors() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, new \ReflectionMethod($fake, 'add'), new Arguments([1]), [new FakeInterceptor, new FakeInterceptor]); + $invocation = new ReflectiveMethodInvocation($fake, 'add', new Arguments([1]), [new FakeInterceptor, new FakeInterceptor]); $invocation->proceed(); $this->assertSame(1, $fake->a); } From 711957136e0ade21173db3bd18caadc5996de81e Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:17:37 +0900 Subject: [PATCH 03/13] replace ReflectionMethod to call_user_func_array --- src/ReflectiveMethodInvocation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index e9f2918a..716d4abc 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -93,7 +93,7 @@ public function getNamedArguments() : \ArrayObject public function proceed() { if ($this->interceptors === []) { - return (new ReflectionMethod($this->object, $this->method))->invokeArgs($this->object, $this->arguments->getArrayCopy()); + return call_user_func_array([$this->object, $this->method], $this->arguments->getArrayCopy()); } $interceptor = array_shift($this->interceptors); From ccc91e0152845ebfdd874cc69b0c458eb8368130 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:26:32 +0900 Subject: [PATCH 04/13] replace Arguments native ArrayObject --- src/Arguments.php | 13 ------------- src/ReflectiveMethodInvocation.php | 6 +++--- template/AopTemplate.php | 2 +- tests/Fake/FakeWeaved.php | 2 +- tests/ReflectiveMethodInvocationTest.php | 6 +++--- 5 files changed, 8 insertions(+), 21 deletions(-) delete mode 100644 src/Arguments.php diff --git a/src/Arguments.php b/src/Arguments.php deleted file mode 100644 index 2fdccfd8..00000000 --- a/src/Arguments.php +++ /dev/null @@ -1,13 +0,0 @@ -object = $object; diff --git a/template/AopTemplate.php b/template/AopTemplate.php index c0008abc..cb24db92 100644 --- a/template/AopTemplate.php +++ b/template/AopTemplate.php @@ -40,7 +40,7 @@ public function templateMethod($a) $this->isIntercepting = false; // invoke interceptor - $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, new \Ray\Aop\Arguments(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); + $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, new \ArrayObject(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); $this->isIntercepting = true; return $result; diff --git a/tests/Fake/FakeWeaved.php b/tests/Fake/FakeWeaved.php index a83fc6a4..f823f61d 100644 --- a/tests/Fake/FakeWeaved.php +++ b/tests/Fake/FakeWeaved.php @@ -27,7 +27,7 @@ public function returnSame($a) $invocation = new ReflectiveMethodInvocation( $this, new \ReflectionMethod($this, __FUNCTION__), - new Arguments(func_get_args()), + new \ArrayObject(func_get_args()), $interceptors ); diff --git a/tests/ReflectiveMethodInvocationTest.php b/tests/ReflectiveMethodInvocationTest.php index eab49f75..8872e341 100644 --- a/tests/ReflectiveMethodInvocationTest.php +++ b/tests/ReflectiveMethodInvocationTest.php @@ -26,7 +26,7 @@ protected function setUp() { parent::setUp(); $this->fake = new FakeClass; - $this->invocation = new ReflectiveMethodInvocation($this->fake, 'add', new Arguments([1])); + $this->invocation = new ReflectiveMethodInvocation($this->fake, 'add', new \ArrayObject([1])); } public function testGetMethod() @@ -70,7 +70,7 @@ public function testGetThis() public function testGetParentMethod() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, 'add', new Arguments([1])); + $invocation = new ReflectiveMethodInvocation($fake, 'add', new \ArrayObject([1])); $method = $invocation->getMethod(); $this->assertSame(FakeClass::class, $method->class); $this->assertSame('add', $method->name); @@ -79,7 +79,7 @@ public function testGetParentMethod() public function testProceedMultipleInterceptors() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, 'add', new Arguments([1]), [new FakeInterceptor, new FakeInterceptor]); + $invocation = new ReflectiveMethodInvocation($fake, 'add', new \ArrayObject([1]), [new FakeInterceptor, new FakeInterceptor]); $invocation->proceed(); $this->assertSame(1, $fake->a); } From bf23bcc68cd3d58b743c46551117cfe818e30575 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:33:55 +0900 Subject: [PATCH 05/13] take array instead of ArrayObject --- src/ReflectiveMethodInvocation.php | 6 +++--- template/AopTemplate.php | 2 +- tests/ReflectiveMethodInvocationTest.php | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index c9006a34..db9ad945 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -33,18 +33,18 @@ final class ReflectiveMethodInvocation implements MethodInvocation /** * @param object $object * @param string $method - * @param \ArrayObject $arguments + * @param array $arguments * @param MethodInterceptor[] $interceptors */ public function __construct( $object, string $method, - \ArrayObject $arguments, + array $arguments, array $interceptors = [] ) { $this->object = $object; $this->method = $method; - $this->arguments = $arguments; + $this->arguments = new \ArrayObject($arguments); $this->interceptors = $interceptors; } diff --git a/template/AopTemplate.php b/template/AopTemplate.php index cb24db92..13f177b9 100644 --- a/template/AopTemplate.php +++ b/template/AopTemplate.php @@ -40,7 +40,7 @@ public function templateMethod($a) $this->isIntercepting = false; // invoke interceptor - $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, new \ArrayObject(func_get_args()), $this->bindings[__FUNCTION__]))->proceed(); + $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, func_get_args(), $this->bindings[__FUNCTION__]))->proceed(); $this->isIntercepting = true; return $result; diff --git a/tests/ReflectiveMethodInvocationTest.php b/tests/ReflectiveMethodInvocationTest.php index 8872e341..5415b929 100644 --- a/tests/ReflectiveMethodInvocationTest.php +++ b/tests/ReflectiveMethodInvocationTest.php @@ -26,7 +26,7 @@ protected function setUp() { parent::setUp(); $this->fake = new FakeClass; - $this->invocation = new ReflectiveMethodInvocation($this->fake, 'add', new \ArrayObject([1])); + $this->invocation = new ReflectiveMethodInvocation($this->fake, 'add', [1]); } public function testGetMethod() @@ -70,7 +70,7 @@ public function testGetThis() public function testGetParentMethod() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, 'add', new \ArrayObject([1])); + $invocation = new ReflectiveMethodInvocation($fake, 'add', [1]); $method = $invocation->getMethod(); $this->assertSame(FakeClass::class, $method->class); $this->assertSame('add', $method->name); @@ -79,7 +79,7 @@ public function testGetParentMethod() public function testProceedMultipleInterceptors() { $fake = new FakeWeavedClass; - $invocation = new ReflectiveMethodInvocation($fake, 'add', new \ArrayObject([1]), [new FakeInterceptor, new FakeInterceptor]); + $invocation = new ReflectiveMethodInvocation($fake, 'add', [1], [new FakeInterceptor, new FakeInterceptor]); $invocation->proceed(); $this->assertSame(1, $fake->a); } From 3613c97cd8b90d7c9e10bec16cff284228502764 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:42:10 +0900 Subject: [PATCH 06/13] add testInterceptorCanChangeArgument test --- tests/CompilerTest.php | 8 ++++++++ tests/Fake/FakeChangeArgsInterceptor.php | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/Fake/FakeChangeArgsInterceptor.php diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 01cfe705..b192ce4d 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -261,4 +261,12 @@ public function testMethodAnnotationReaderReturnNull() $this->assertNull(FakeMethodAnnotationReaderInterceptor::$methodAnnotation); $this->assertCount(0, FakeMethodAnnotationReaderInterceptor::$methodAnnotations); } + + public function testInterceptorCanChangeArgument() + { + $bind = (new Bind)->bindInterceptors('returnSame', [new FakeChangeArgsInterceptor()]); + $compiler = new Compiler($_ENV['TMP_DIR']); + $mock = $compiler->newInstance(FakeMock::class, [], $bind); + $this->assertSame('changed', $mock->returnSame(1)); + } } diff --git a/tests/Fake/FakeChangeArgsInterceptor.php b/tests/Fake/FakeChangeArgsInterceptor.php new file mode 100644 index 00000000..eae84763 --- /dev/null +++ b/tests/Fake/FakeChangeArgsInterceptor.php @@ -0,0 +1,13 @@ +getArguments(); + $args[0] = 'changed'; + + return $invocation->proceed(); + } +} From 50bf1d5740d8ca1e1d7092cb6f1d216ab0ed4fa3 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:51:49 +0900 Subject: [PATCH 07/13] cast (array) --- src/ReflectiveMethodInvocation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index db9ad945..83c49820 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -93,7 +93,7 @@ public function getNamedArguments() : \ArrayObject public function proceed() { if ($this->interceptors === []) { - return call_user_func_array([$this->object, $this->method], $this->arguments->getArrayCopy()); + return call_user_func_array([$this->object, $this->method], (array) $this->arguments); } $interceptor = array_shift($this->interceptors); From e94b309e45a9c6f2737b1ab441df09cd2e6e590c Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 05:55:42 +0900 Subject: [PATCH 08/13] return ArrayObject on demand argument is still array unless user called getArguments, which enable to change argument in interceptor. --- src/ReflectiveMethodInvocation.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ReflectiveMethodInvocation.php b/src/ReflectiveMethodInvocation.php index 83c49820..8c092bc8 100644 --- a/src/ReflectiveMethodInvocation.php +++ b/src/ReflectiveMethodInvocation.php @@ -16,7 +16,7 @@ final class ReflectiveMethodInvocation implements MethodInvocation private $object; /** - * @var \ArrayObject + * @var array|\ArrayObject */ private $arguments; @@ -44,7 +44,7 @@ public function __construct( ) { $this->object = $object; $this->method = $method; - $this->arguments = new \ArrayObject($arguments); + $this->arguments = $arguments; $this->interceptors = $interceptors; } @@ -69,6 +69,8 @@ public function getMethod() : \ReflectionMethod */ public function getArguments() : \ArrayObject { + $this->arguments = new \ArrayObject($this->arguments); + return $this->arguments; } From 8b535e15b35ecdafb0e58afac1f2589b80504f52 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 08:29:55 +0900 Subject: [PATCH 09/13] add AopTemplateConverter for readability of generated code and perfomance gain --- src/AopTemplateConverter.php | 58 ++++++++++++++++++++++++++++++++++++ src/CodeGenMethod.php | 12 ++++++-- template/AopTemplate.php | 7 ++--- 3 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 src/AopTemplateConverter.php diff --git a/src/AopTemplateConverter.php b/src/AopTemplateConverter.php new file mode 100644 index 00000000..47229b25 --- /dev/null +++ b/src/AopTemplateConverter.php @@ -0,0 +1,58 @@ +method = $method->name; + $proceedArg = []; + foreach ($method->getParameters() as $parameter) { + $this->args[] = new Arg(new Variable($parameter->name)); + $proceedArg[] = new ArrayItem(new Variable($parameter->name)); + } + $this->proceedArg = new Arg(new Node\Expr\Array_($proceedArg)); + } + + public function enterNode(Node $node) + { + if ($node instanceof StaticCall && $node->name === 'templateMethod') { + $node->name = $this->method; + $node->args = $this->args; + + return $node; + } + // change ReflectiveMethodInvocation 2nd parameter + if ($node instanceof MethodCall && $node->name === 'proceed' && isset($node->var)) { + $node->var->args[2] = $this->proceedArg; + + return $node; + } + } +} diff --git a/src/CodeGenMethod.php b/src/CodeGenMethod.php index a3351b64..e5ff1ef0 100644 --- a/src/CodeGenMethod.php +++ b/src/CodeGenMethod.php @@ -15,6 +15,7 @@ use PhpParser\Comment\Doc; use PhpParser\Node\NullableType; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\NodeTraverser; use PhpParser\Parser; use PhpParser\PrettyPrinter\Standard; use Ray\Aop\Annotation\AbstractAssisted; @@ -100,7 +101,7 @@ private function getMethod(\ReflectionMethod $method) if ($returnType instanceof \ReflectionType) { $this->setReturnType($returnType, $methodStmt); } - $methodInsideStatements = $this->getMethodInsideStatement(); + $methodInsideStatements = $this->getMethodInsideStatement($method); $methodStmt->addStmts($methodInsideStatements); return $this->addMethodDocComment($methodStmt, $method); @@ -135,14 +136,19 @@ private function addMethodDocComment(Method $methodStmt, \ReflectionMethod $meth /** * @return \PhpParser\Node[] */ - private function getMethodInsideStatement() : array + private function getMethodInsideStatement(\ReflectionMethod $method) : array { + $traverser = new NodeTraverser; + $traverser->addVisitor(new AopTemplateConverter($method)); + $code = file_get_contents(dirname(__DIR__) . '/template/AopTemplate.php'); $node = $this->parser->parse($code)[0]; /* @var $node \PhpParser\Node\Stmt\Class_ */ $node = $node->getMethods()[0]; + // traverse + $stmts = $traverser->traverse($node->stmts); - return $node->stmts; + return $stmts; } /** diff --git a/template/AopTemplate.php b/template/AopTemplate.php index 13f177b9..6eba9595 100644 --- a/template/AopTemplate.php +++ b/template/AopTemplate.php @@ -29,18 +29,17 @@ class AopTemplate extends \Ray\Aop\FakeMock implements Ray\Aop\WeavedInterface * * @param mixed $a */ - public function templateMethod($a) + public function templateMethod($a, $b) { if ($this->isIntercepting === false) { $this->isIntercepting = true; - // call original method - return call_user_func_array('parent::' . __FUNCTION__, func_get_args()); + return parent::templateMethod($a, $b); } $this->isIntercepting = false; // invoke interceptor - $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, func_get_args(), $this->bindings[__FUNCTION__]))->proceed(); + $result = (new \Ray\Aop\ReflectiveMethodInvocation($this, __FUNCTION__, [$a, $b], $this->bindings[__FUNCTION__]))->proceed(); $this->isIntercepting = true; return $result; From 1f5fd8a763ae64cf4d3af0dfcb176bef69e0fefe Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 08:30:14 +0900 Subject: [PATCH 10/13] fix cs --- tests/CompilerTest.php | 4 +++- tests/Fake/FakeWeaved.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index b192ce4d..81981a5e 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -266,7 +266,9 @@ public function testInterceptorCanChangeArgument() { $bind = (new Bind)->bindInterceptors('returnSame', [new FakeChangeArgsInterceptor()]); $compiler = new Compiler($_ENV['TMP_DIR']); + /** @var FakeMock $mock */ $mock = $compiler->newInstance(FakeMock::class, [], $bind); - $this->assertSame('changed', $mock->returnSame(1)); + $mock->returnSame(1); + $this->assertSame('changed', $mock->returnSame(1)); } } diff --git a/tests/Fake/FakeWeaved.php b/tests/Fake/FakeWeaved.php index f823f61d..6b557c6e 100644 --- a/tests/Fake/FakeWeaved.php +++ b/tests/Fake/FakeWeaved.php @@ -27,7 +27,7 @@ public function returnSame($a) $invocation = new ReflectiveMethodInvocation( $this, new \ReflectionMethod($this, __FUNCTION__), - new \ArrayObject(func_get_args()), + func_get_args(), $interceptors ); From 61d765a1c2d5d96ad11540f4601054f3dec837ca Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 09:49:05 +0900 Subject: [PATCH 11/13] ignoreErrors phpstan error --- phpstan.neon | 2 ++ src/AopTemplateConverter.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index a6d9041e..f0eb3c14 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,5 @@ parameters: excludes_analyse: - %currentWorkingDirectory%/tests/tmp/* + ignoreErrors: + - '#Access to an undefined property PhpParser\\Node\\Expr::\$args#' \ No newline at end of file diff --git a/src/AopTemplateConverter.php b/src/AopTemplateConverter.php index 47229b25..03eb6228 100644 --- a/src/AopTemplateConverter.php +++ b/src/AopTemplateConverter.php @@ -49,7 +49,7 @@ public function enterNode(Node $node) return $node; } // change ReflectiveMethodInvocation 2nd parameter - if ($node instanceof MethodCall && $node->name === 'proceed' && isset($node->var)) { + if ($node instanceof MethodCall && $node->name === 'proceed') { $node->var->args[2] = $this->proceedArg; return $node; From 82dd70e62ca6ee8ec2d5274ede1fd034d62e26d7 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 10:04:11 +0900 Subject: [PATCH 12/13] update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c34b7f15..754c0310 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,6 @@ before_script: script: - ./vendor/bin/phpunit --coverage-clover=coverage.clover; - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${TRAVIS_COMMIT_RANGE}") & if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then IFS=$'\n' EXTRA_ARGS=('--path-mode=intersection' '--' ${CHANGED_FILES[@]}); fi & php php-cs-fixer-v2.phar fix --config=.php_cs -v --dry-run --stop-on-violation --using-cache=no "${EXTRA_ARGS[@]}"; fi - - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then ./vendor/bin/phpstan analyse -l max src --no-progress --no-interaction; fi + - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then ./vendor/bin/phpstan analyse -l max -c phpstan.neon src --no-progress --no-interaction; fi after_script: - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi From d755e75dd52b5144aa0f442a21237b339a369725 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 27 Apr 2018 10:47:09 +0900 Subject: [PATCH 13/13] extract method --- src/AopTemplateConverter.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AopTemplateConverter.php b/src/AopTemplateConverter.php index 03eb6228..2c33cba6 100644 --- a/src/AopTemplateConverter.php +++ b/src/AopTemplateConverter.php @@ -48,11 +48,18 @@ public function enterNode(Node $node) return $node; } - // change ReflectiveMethodInvocation 2nd parameter + + return $this->updateReflectiveMethodInvocation2ndParam($node); + } + + private function updateReflectiveMethodInvocation2ndParam(Node $node) : Node + { if ($node instanceof MethodCall && $node->name === 'proceed') { $node->var->args[2] = $this->proceedArg; return $node; } + + return $node; } }