Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/44'
Browse files Browse the repository at this point in the history
Close #44
  • Loading branch information
weierophinney committed May 1, 2018
2 parents da33213 + dd23207 commit 4b2ecb7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/ClassFileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions test/ClassFileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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`");
}
}
15 changes: 15 additions & 0 deletions test/TestAsset/ContainsUseFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* @see https://github.com/zendframework/zend-file for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-file/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\File\TestAsset;

use function strlen;

class ContainsUseFunction
{

}

0 comments on commit 4b2ecb7

Please sign in to comment.