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

Don't ignore files with use function #44

Merged
merged 1 commit into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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 `use function`

## 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`");
}
}
10 changes: 10 additions & 0 deletions test/TestAsset/ContainsUseFunction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace ZendTest\File\TestAsset;

use function strlen;

class ContainsUseFunction
{

}