diff --git a/src/Hal/Metric/Helper/RoleOfMethodDetector.php b/src/Hal/Metric/Helper/RoleOfMethodDetector.php index 8df4d77d..00128ff3 100644 --- a/src/Hal/Metric/Helper/RoleOfMethodDetector.php +++ b/src/Hal/Metric/Helper/RoleOfMethodDetector.php @@ -1,7 +1,6 @@ [ - 'PhpParser\\Node\\Stmt\\ClassMethod', - 'PhpParser\\Node\\Stmt\\Return_', - 'PhpParser\\Node\\Expr\\PropertyFetch', - 'PhpParser\\Node\\Expr\\Variable', + [ + 'PhpParser\\Node\\Stmt\\ClassMethod', + 'PhpParser\\Node\\Stmt\\Return_', + 'PhpParser\\Node\\Expr\\PropertyFetch', + 'PhpParser\\Node\\Expr\\Variable', + ], + [ + 'PhpParser\\Node\\Stmt\\ClassMethod', + 'PhpParser\\Node\\Stmt\\Return_', + 'PhpParser\\Node\\Expr\\PropertyFetch', + 'PhpParser\\Node\\Expr\\Variable', + 'PhpParser\\Node\\Name', + ], ], 'setter' => [ - 'PhpParser\\Node\\Stmt\\ClassMethod', - 'PhpParser\\Node\\Expr\\Assign', - 'PhpParser\\Node\\Expr\\Variable', - 'PhpParser\\Node\\Expr\\PropertyFetch', - 'PhpParser\\Node\\Expr\\Variable', - 'PhpParser\\Node\\Param', + [ + 'PhpParser\\Node\\Stmt\\ClassMethod', + 'PhpParser\\Node\\Expr\\Assign', + 'PhpParser\\Node\\Expr\\Variable', + 'PhpParser\\Node\\Expr\\PropertyFetch', + 'PhpParser\\Node\\Expr\\Variable', + 'PhpParser\\Node\\Param', + ], + [ + 'PhpParser\\Node\\Stmt\\ClassMethod', + 'PhpParser\\Node\\Expr\\Assign', + 'PhpParser\\Node\\Expr\\Variable', + 'PhpParser\\Node\\Expr\\PropertyFetch', + 'PhpParser\\Node\\Expr\\Variable', + 'PhpParser\\Node\\Param', + 'PhpParser\\Node\\Name', + ] ] ]; @@ -40,8 +58,7 @@ class RoleOfMethodDetector */ public function detects($node) { - - if (!$node instanceof ClassMethod) { + if (! $node instanceof ClassMethod) { return null; } @@ -65,13 +82,12 @@ public function detects($node) $fingerprintOfMethod = array_reverse($fingerprintOfMethod); // compare with database of fingerprints - foreach ($this->fingerprints as $type => $fingerprint) { - if ($fingerprint == $fingerprintOfMethod) { + foreach ($this->fingerprints as $type => $fingerprints) { + if (in_array($fingerprintOfMethod, $fingerprints, true)) { return $type; } } return null; } - -} \ No newline at end of file +} diff --git a/tests/Metric/Helper/RoleOfMethodDetectorTest.php b/tests/Metric/Helper/RoleOfMethodDetectorTest.php index 5fd1f298..58a5eb5c 100644 --- a/tests/Metric/Helper/RoleOfMethodDetectorTest.php +++ b/tests/Metric/Helper/RoleOfMethodDetectorTest.php @@ -13,7 +13,6 @@ */ class RoleOfMethodDetectorTest extends \PHPUnit_Framework_TestCase { - /** * @dataProvider provideExamples */ @@ -38,7 +37,7 @@ public function testICanDetectRoleOfMethod($expected, $code) public function provideExamples() { - return [ + $examples = [ ['getter', 'name; } } ?>'], ['getter', 'name; } } ?>'], ['getter', 'name; } } ?>'], @@ -46,7 +45,13 @@ public function provideExamples() ['setter', 'name = (string) $name; } } ?>'], ['setter', 'name = (string) $name; return $this; } } ?>'], [null, 'name = (string) $name * 3; } } ?>'], - ]; + if (version_compare(PHP_VERSION, '7.0.0') >= 0) { + $examples[] = ['getter', 'name; } }']; + $examples[] = ['setter', 'name = $name; } }']; + $examples[] = ['getter', 'name; } }']; + $examples[] = ['setter', 'name = $name; } }']; + } + return $examples; } }