Skip to content

Commit

Permalink
Provide a fix for issue zendframework#70
Browse files Browse the repository at this point in the history
- Added a failing test case, per zendframework#70.
- Discovered that the structure addressed can be either an array
  (existing assumption) or a string.
- Updated the assignment to check for array before assigning, and use
  the string value if present instead.
  • Loading branch information
weierophinney committed Jun 27, 2016
1 parent ca15548 commit e71c589
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Scanner/TokenArrayScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,9 @@ protected function scan()
&& $infos[$infoIndex]['type'] === 'class'
|| ($tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function'))
) {
$infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1];
$infos[$infoIndex]['shortName'] = is_array($tokens[$tokenIndex + 2])
? $tokens[$tokenIndex + 2][1]
: $tokens[$tokenIndex + 2];
$infos[$infoIndex]['name'] = (($namespace !== null)
? $namespace . '\\'
: '') . $infos[$infoIndex]['shortName'];
Expand Down
12 changes: 12 additions & 0 deletions test/Reflection/FileReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,16 @@ public function testFileCanReflectFileWithUses()
];
$this->assertSame($expected, $reflectionFile->getUses());
}

/**
* @group 70
* @group 43
*/
public function testFileReflectionShouldNotRaiseNoticesWhenReflectingClosures()
{
require_once __DIR__ . '/TestAsset/issue-70.php';
$r = new FileReflection(__DIR__ . '/TestAsset/issue-70.php');
$this->assertContains('spl_autoload_register', $r->getContents());
$this->assertContains('function ()', $r->getContents());
}
}
9 changes: 9 additions & 0 deletions test/Reflection/TestAsset/issue-70.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* @link http://github.com/zendframework/zend-code for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

spl_autoload_register(function () {
});

0 comments on commit e71c589

Please sign in to comment.