From 1db03d8d7b8312bbe11fd2637bf1d693320b41d7 Mon Sep 17 00:00:00 2001 From: Dalibor Date: Tue, 10 Oct 2017 16:41:50 +0200 Subject: [PATCH] Support scalar types --- src/Kdyby/Aop/PhpGenerator/PointcutMethod.php | 4 +++- tests/KdybyTests/Aop/AdvisedClassType.phpt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Kdyby/Aop/PhpGenerator/PointcutMethod.php b/src/Kdyby/Aop/PhpGenerator/PointcutMethod.php index 3330ceb..2b73dc8 100644 --- a/src/Kdyby/Aop/PhpGenerator/PointcutMethod.php +++ b/src/Kdyby/Aop/PhpGenerator/PointcutMethod.php @@ -244,7 +244,9 @@ public static function expandTypeHints(\ReflectionMethod $from, Code\Method $met foreach ($from->getParameters() as $paramRefl) { try { - $parameters[$paramRefl->getName()]->setTypeHint($paramRefl->isArray() ? 'array' : ($paramRefl->getClass() ? '\\' . $paramRefl->getClass()->getName() : '')); + if(!in_array($parameters[$paramRefl->getName()]->getTypeHint(),['boolean', 'integer', 'float', 'string', 'object', 'int', 'bool', ])) { + $parameters[$paramRefl->getName()]->setTypeHint($paramRefl->isArray() ? 'array' : ($paramRefl->getClass() ? '\\' . $paramRefl->getClass()->getName() : '')); + } } catch (\ReflectionException $e) { if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) { $parameters[$paramRefl->getName()]->setTypeHint('\\' . $m[1]); diff --git a/tests/KdybyTests/Aop/AdvisedClassType.phpt b/tests/KdybyTests/Aop/AdvisedClassType.phpt index 8c4faa8..22da09f 100644 --- a/tests/KdybyTests/Aop/AdvisedClassType.phpt +++ b/tests/KdybyTests/Aop/AdvisedClassType.phpt @@ -29,10 +29,9 @@ class AdvisedClassTypeTest extends Tester\TestCase $testClass = ClassType::from(TestClass::class); $method = Kdyby\Aop\PhpGenerator\AdvisedClassType::setMethodInstance($testClass, $testClass->getMethod('first')); + $string = $methodCode = $method->__toString(); Assert::count(2, $method->getParameters()); } - - } class TestClass