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

Commit 4b2ecb7

Browse files
committed
Merge branch 'hotfix/44'
Close #44
2 parents da33213 + dd23207 commit 4b2ecb7

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.8.1 - TBD
5+
## 2.8.1 - 2018-05-01
66

77
### Added
88

@@ -22,7 +22,9 @@ All notable changes to this project will be documented in this file, in reverse
2222

2323
### Fixed
2424

25-
- Nothing.
25+
- [#44](https://github.com/zendframework/zend-file/pull/44) fixes an issue where
26+
ClassFileLocator would skip the file (otherwise valid class file) containing a
27+
`use function` declaration.
2628

2729
## 2.8.0 - 2018-04-25
2830

src/ClassFileLocator.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ public function accept()
126126
}
127127
break;
128128
case T_FUNCTION:
129-
$inFunctionDeclaration = true;
129+
// `use function` should not enter function context
130+
if ($i < 2 || ! is_array($tokens[$i - 2]) || $tokens[$i - 2][0] !== T_USE) {
131+
$inFunctionDeclaration = true;
132+
}
130133
break;
131134
case T_TRAIT:
132135
case T_CLASS:

test/ClassFileLocatorTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,17 @@ public function testIgnoresMethodsNamedAfterKeywords()
196196

197197
$this->assertEquals($expected, $classNames, '', 0.0, 10, true);
198198
}
199+
200+
public function testIterationFindsClassInAFileWithUseFunction()
201+
{
202+
$locator = new ClassFileLocator(__DIR__);
203+
$found = false;
204+
205+
foreach ($locator as $file) {
206+
if (preg_match('/ContainsUseFunction\.php$/', $file->getFilename())) {
207+
$found = true;
208+
}
209+
}
210+
$this->assertTrue($found, "Failed to find a file that contains `use function`");
211+
}
199212
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-file for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-file/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendTest\File\TestAsset;
9+
10+
use function strlen;
11+
12+
class ContainsUseFunction
13+
{
14+
15+
}

0 commit comments

Comments
 (0)