From 16293e05fa2ac2e9437c42b47ee3f442b4fe2899 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 15 Aug 2017 12:09:51 +0900 Subject: [PATCH 1/6] add php 7.2 support --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 632af6dd..e356ef4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ sudo: false dist: trusty php: - 7.1 + - 7.2 cache: directories: - vendor From 265794d2b9af57e4aa4c4f835a0f6641450935f1 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 20 Aug 2017 12:40:40 +0900 Subject: [PATCH 2/6] add php7.0 support (again) --- .travis.yml | 3 ++- composer.json | 4 ++-- src/Bind.php | 6 +++--- src/CodeGenMethod.php | 8 ++++---- src/CodeGenVisitor.php | 2 +- src/Matcher/AnyMatcher.php | 2 +- src/ReflectionClass.php | 2 +- src/ReflectionMethod.php | 2 +- 8 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index e356ef4b..49e04a54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: php sudo: false dist: trusty php: + - 7.0 - 7.1 - 7.2 cache: @@ -17,7 +18,7 @@ before_script: - composer update $DEPENDENCIES script: - ./vendor/bin/phpunit --coverage-clover=coverage.clover; - - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar && php php-cs-fixer-v2.phar fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi + - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar && php php-cs-fixer.phar fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; 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 diff --git a/composer.json b/composer.json index 21bb7824..aa48146f 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ } ], "require": { - "php": ">=7.1.0", - "doctrine/annotations": "^1.3", + "php": ">=7.0.0", + "doctrine/annotations": "^1.2", "nikic/php-parser": "^3.0" }, "require-dev": { diff --git a/src/Bind.php b/src/Bind.php index e8cbb872..e5c7bcff 100644 --- a/src/Bind.php +++ b/src/Bind.php @@ -87,7 +87,7 @@ public function getAnnotationPointcuts(array &$pointcuts) : array return $keyPointcuts; } - private function annotatedMethodsMatch(\ReflectionClass $class, array &$pointcuts) : void + private function annotatedMethodsMatch(\ReflectionClass $class, array &$pointcuts) { $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { @@ -95,7 +95,7 @@ private function annotatedMethodsMatch(\ReflectionClass $class, array &$pointcut } } - private function annotatedMethodMatch(\ReflectionClass $class, \ReflectionMethod $method, array $pointcuts) : void + private function annotatedMethodMatch(\ReflectionClass $class, \ReflectionMethod $method, array $pointcuts) { $annotations = $this->reader->getMethodAnnotations($method); // priority bind @@ -113,7 +113,7 @@ private function annotatedMethodMatch(\ReflectionClass $class, \ReflectionMethod } } - private function annotatedMethodMatchBind(\ReflectionClass $class, \ReflectionMethod $method, Pointcut $pointCut) : void + private function annotatedMethodMatchBind(\ReflectionClass $class, \ReflectionMethod $method, Pointcut $pointCut) { $isMethodMatch = $pointCut->methodMatcher->matchesMethod($method, $pointCut->methodMatcher->getArguments()); if (! $isMethodMatch) { diff --git a/src/CodeGenMethod.php b/src/CodeGenMethod.php index 3c594417..f7a8209e 100644 --- a/src/CodeGenMethod.php +++ b/src/CodeGenMethod.php @@ -148,7 +148,7 @@ private function getMethodInsideStatement() : array /** * @codeCoverageIgnore */ - private function setTypeHint(\ReflectionParameter $param, Param $paramStmt, \ReflectionClass $typeHint = null) : void + private function setTypeHint(\ReflectionParameter $param, Param $paramStmt, \ReflectionClass $typeHint = null) { if ($typeHint) { $paramStmt->setTypeHint($typeHint->name); @@ -161,7 +161,7 @@ private function setTypeHint(\ReflectionParameter $param, Param $paramStmt, \Ref } } - private function setDefault(\ReflectionParameter $param, Param $paramStmt) : void + private function setDefault(\ReflectionParameter $param, Param $paramStmt) { if ($param->isDefaultValueAvailable()) { $paramStmt->setDefault($param->getDefaultValue()); @@ -173,7 +173,7 @@ private function setDefault(\ReflectionParameter $param, Param $paramStmt) : voi } } - private function setParameterType(\ReflectionParameter $param, Param $paramStmt) : void + private function setParameterType(\ReflectionParameter $param, Param $paramStmt) { $type = $param->getType(); if ($type) { @@ -181,7 +181,7 @@ private function setParameterType(\ReflectionParameter $param, Param $paramStmt) } } - private function setReturnType(\ReflectionType $returnType, Method $methodStmt) : void + private function setReturnType(\ReflectionType $returnType, Method $methodStmt) { $type = $returnType->allowsNull() ? new NullableType($returnType->getName()) : $returnType->getName(); if ($returnType && method_exists($methodStmt, 'setReturnType')) { diff --git a/src/CodeGenVisitor.php b/src/CodeGenVisitor.php index ce18d358..af442660 100644 --- a/src/CodeGenVisitor.php +++ b/src/CodeGenVisitor.php @@ -28,7 +28,7 @@ public function __invoke() : array return $this->selectedNodes; } - public function enterNode(Node $node) : void + public function enterNode(Node $node) { if ($node instanceof Use_ || $node instanceof Declare_) { $this->selectedNodes[] = $node; // @codeCoverageIgnore diff --git a/src/Matcher/AnyMatcher.php b/src/Matcher/AnyMatcher.php index 16109a28..93a32d2b 100644 --- a/src/Matcher/AnyMatcher.php +++ b/src/Matcher/AnyMatcher.php @@ -43,7 +43,7 @@ public function matchesMethod(\ReflectionMethod $method, array $arguments) : boo return ! ($this->isMagicMethod($method->name) || $this->isBuiltinMethod($method->name)); } - private function setBuildInMethods() : void + private function setBuildInMethods() { $methods = (new \ReflectionClass('\ArrayObject'))->getMethods(); foreach ($methods as $method) { diff --git a/src/ReflectionClass.php b/src/ReflectionClass.php index 6ea8a8c2..9e46de0f 100644 --- a/src/ReflectionClass.php +++ b/src/ReflectionClass.php @@ -20,7 +20,7 @@ class ReflectionClass extends \ReflectionClass implements Reader * * @param WeavedInterface $object */ - public function setObject(WeavedInterface $object) : void + public function setObject(WeavedInterface $object) { $this->object = $object; } diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index dd29bbf5..f3657934 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -23,7 +23,7 @@ final class ReflectionMethod extends \ReflectionMethod implements Reader /** * Set dependencies */ - public function setObject(WeavedInterface $object, \ReflectionMethod $method) : void + public function setObject(WeavedInterface $object, \ReflectionMethod $method) { $this->object = $object; $this->method = $method->name; From 5e57b8d34fe823118dc4f3d4075dfff3d6159991 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 20 Aug 2017 13:08:40 +0900 Subject: [PATCH 3/6] string cast over getName() method According to PHP manual (http://php.net/manual/en/class.reflectiontype.php), getName() method is not exists (?) --- src/CodeGenMethod.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/CodeGenMethod.php b/src/CodeGenMethod.php index f7a8209e..d8944ebb 100644 --- a/src/CodeGenMethod.php +++ b/src/CodeGenMethod.php @@ -183,9 +183,7 @@ private function setParameterType(\ReflectionParameter $param, Param $paramStmt) private function setReturnType(\ReflectionType $returnType, Method $methodStmt) { - $type = $returnType->allowsNull() ? new NullableType($returnType->getName()) : $returnType->getName(); - if ($returnType && method_exists($methodStmt, 'setReturnType')) { - $methodStmt->setReturnType($type); // @codeCoverageIgnore - } + $type = $returnType->allowsNull() ? new NullableType($returnType->getName()) : (string) $returnType; + $methodStmt->setReturnType($type); } } From c65d15ab07467a850d4cf88706db3f4d433e55ea Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 20 Aug 2017 13:18:42 +0900 Subject: [PATCH 4/6] exclude php7.1 only test --- phpunit.xml.dist | 1 + tests/CodeGenPhp71Test.php | 48 ++++++++++++++++++++++++++++++++++++++ tests/CodeGenTest.php | 29 ----------------------- 3 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 tests/CodeGenPhp71Test.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b3e21515..6ccdb19a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,6 +2,7 @@ tests + tests/CodeGenPhp71Test.php diff --git a/tests/CodeGenPhp71Test.php b/tests/CodeGenPhp71Test.php new file mode 100644 index 00000000..05f5a6af --- /dev/null +++ b/tests/CodeGenPhp71Test.php @@ -0,0 +1,48 @@ +codeGen = new CodeGen((new ParserFactory)->newInstance(), new BuilderFactory, new Standard); + } + + public function testReturnTypeVoid() + { + $bind = new Bind; + $bind->bindInterceptors('returnTypeVoid', []); + $code = $this->codeGen->generate('a', new \ReflectionClass(FakePhp71ReturnTypeClass::class), $bind); + $expected = 'function returnTypeVoid() : void'; + $this->assertContains($expected, $code); + } + + public function testReturnTypeNullable() + { + $bind = new Bind; + $bind->bindInterceptors('returnNullable', []); + $code = $this->codeGen->generate('a', new \ReflectionClass(FakePhp71ReturnTypeClass::class), $bind); + $expected = 'function returnNullable(string $str) : ?'; + $this->assertContains($expected, $code); + + return $code; + } + + /** + * @depends testReturnTypeNullable + */ + public function testContainsStatement(string $code) + { + $this->assertContains("declare (strict_types=1);\n", $code); + $this->assertContains("use Composer\Autoload;\n", $code); + } +} diff --git a/tests/CodeGenTest.php b/tests/CodeGenTest.php index 7e9056b1..6819006e 100644 --- a/tests/CodeGenTest.php +++ b/tests/CodeGenTest.php @@ -43,33 +43,4 @@ public function testReturnType() $expected = 'function returnTypeArray() : array'; $this->assertContains($expected, $code); } - - public function testReturnTypeVoid() - { - $bind = new Bind; - $bind->bindInterceptors('returnTypeVoid', []); - $code = $this->codeGen->generate('a', new \ReflectionClass(FakePhp71ReturnTypeClass::class), $bind); - $expected = 'function returnTypeVoid() : void'; - $this->assertContains($expected, $code); - } - - public function testReturnTypeNullable() - { - $bind = new Bind; - $bind->bindInterceptors('returnNullable', []); - $code = $this->codeGen->generate('a', new \ReflectionClass(FakePhp71ReturnTypeClass::class), $bind); - $expected = 'function returnNullable(string $str) : ?'; - $this->assertContains($expected, $code); - - return $code; - } - - /** - * @depends testReturnTypeNullable - */ - public function testContainsStatement(string $code) - { - $this->assertContains("declare (strict_types=1);\n", $code); - $this->assertContains("use Composer\Autoload;\n", $code); - } } From a01210c67e24e1cbd80d979e739b181d3f04cc62 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 20 Aug 2017 13:26:53 +0900 Subject: [PATCH 5/6] remove Test suffix to exclude --- phpunit.xml.dist | 2 +- tests/{CodeGenPhp71Test.php => CodeGenPhp71.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/{CodeGenPhp71Test.php => CodeGenPhp71.php} (97%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6ccdb19a..bcea0caa 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ tests - tests/CodeGenPhp71Test.php + tests/CodeGenPhp71.php diff --git a/tests/CodeGenPhp71Test.php b/tests/CodeGenPhp71.php similarity index 97% rename from tests/CodeGenPhp71Test.php rename to tests/CodeGenPhp71.php index 05f5a6af..e2185390 100644 --- a/tests/CodeGenPhp71Test.php +++ b/tests/CodeGenPhp71.php @@ -5,7 +5,7 @@ use PhpParser\PrettyPrinter\Standard; use PHPUnit\Framework\TestCase; -class CodeGenPhp71Test extends TestCase +class CodeGenPhp71 extends TestCase { /** * @var CodeGen From 114be80fd499f6d6a6cbe53bec5379cb6c389c7f Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sun, 20 Aug 2017 13:34:32 +0900 Subject: [PATCH 6/6] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8fbae812..3af232f0 100644 --- a/README.md +++ b/README.md @@ -235,7 +235,7 @@ The recommended way to install Ray.Aop is through [Composer](https://github.com/ ```bash # Add Ray.Aop as a dependency -$ composer require ray/aop ~2.0 +$ composer require ray/aop ^2.0 ``` ## Testing Ray.Aop