diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a342e7..36555f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.8.1 - TBD +## 2.8.1 - 2018-05-01 ### Added @@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#44](https://github.com/zendframework/zend-file/pull/44) fixes an issue where + ClassFileLocator would skip the file (otherwise valid class file) containing a + `use function` declaration. ## 2.8.0 - 2018-04-25 diff --git a/src/ClassFileLocator.php b/src/ClassFileLocator.php index 8ac5f32..c224367 100644 --- a/src/ClassFileLocator.php +++ b/src/ClassFileLocator.php @@ -126,7 +126,10 @@ public function accept() } break; case T_FUNCTION: - $inFunctionDeclaration = true; + // `use function` should not enter function context + if ($i < 2 || ! is_array($tokens[$i - 2]) || $tokens[$i - 2][0] !== T_USE) { + $inFunctionDeclaration = true; + } break; case T_TRAIT: case T_CLASS: diff --git a/test/ClassFileLocatorTest.php b/test/ClassFileLocatorTest.php index d4f4b4d..8d176d1 100644 --- a/test/ClassFileLocatorTest.php +++ b/test/ClassFileLocatorTest.php @@ -196,4 +196,17 @@ public function testIgnoresMethodsNamedAfterKeywords() $this->assertEquals($expected, $classNames, '', 0.0, 10, true); } + + public function testIterationFindsClassInAFileWithUseFunction() + { + $locator = new ClassFileLocator(__DIR__); + $found = false; + + foreach ($locator as $file) { + if (preg_match('/ContainsUseFunction\.php$/', $file->getFilename())) { + $found = true; + } + } + $this->assertTrue($found, "Failed to find a file that contains `use function`"); + } } diff --git a/test/TestAsset/ContainsUseFunction.php b/test/TestAsset/ContainsUseFunction.php new file mode 100644 index 0000000..b9e4754 --- /dev/null +++ b/test/TestAsset/ContainsUseFunction.php @@ -0,0 +1,15 @@ +