Skip to content

Commit

Permalink
Merge pull request #77 from koriym/php7.0
Browse files Browse the repository at this point in the history
Support PHP 7.0
  • Loading branch information
koriym authored Aug 20, 2017
2 parents 6bbd709 + 114be80 commit e4a5965
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ language: php
sudo: false
dist: trusty
php:
- 7.0
- 7.1
- 7.2
cache:
directories:
- vendor
Expand All @@ -16,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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
<file phpVersion="7.1.0" phpVersionOperator=">=">tests/CodeGenPhp71.php</file>
</testsuite>
</testsuites>
<filter>
Expand Down
6 changes: 3 additions & 3 deletions src/Bind.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ 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) {
$this->annotatedMethodMatch($class, $method, $pointcuts);
}
}

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
Expand All @@ -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) {
Expand Down
14 changes: 6 additions & 8 deletions src/CodeGenMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -173,19 +173,17 @@ 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) {
$paramStmt->setTypeHint((string) $type);
}
}

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')) {
$methodStmt->setReturnType($type); // @codeCoverageIgnore
}
$type = $returnType->allowsNull() ? new NullableType($returnType->getName()) : (string) $returnType;
$methodStmt->setReturnType($type);
}
}
2 changes: 1 addition & 1 deletion src/CodeGenVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Matcher/AnyMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
48 changes: 48 additions & 0 deletions tests/CodeGenPhp71.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Ray\Aop;

use PhpParser\BuilderFactory;
use PhpParser\PrettyPrinter\Standard;
use PHPUnit\Framework\TestCase;

class CodeGenPhp71 extends TestCase
{
/**
* @var CodeGen
*/
private $codeGen;

public function setUp()
{
$this->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);
}
}
29 changes: 0 additions & 29 deletions tests/CodeGenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit e4a5965

Please sign in to comment.