Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feature/4989' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Aug 21, 2013
2 parents 34abf27 + 0730d85 commit d5b2175
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
10 changes: 9 additions & 1 deletion library/Zend/Code/Scanner/TokenArrayScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ protected function scan()
throw new Exception\RuntimeException('No tokens were provided');
}

/**
* Define PHP 5.4 'trait' token constant.
*/
if (!defined('T_TRAIT')) {
define('T_TRAIT', 42001);
}

/**
* Variables & Setup
*/
Expand Down Expand Up @@ -552,6 +559,7 @@ protected function scan()
case T_ABSTRACT:
case T_CLASS:
case T_INTERFACE:
case T_TRAIT:

$infos[$infoIndex] = array(
'type' => ($tokenType === T_FUNCTION) ? 'function' : 'class',
Expand All @@ -573,7 +581,7 @@ protected function scan()

// process the name
if ($infos[$infoIndex]['shortName'] == ''
&& (($tokenType === T_CLASS || $tokenType === T_INTERFACE) && $infos[$infoIndex]['type'] === 'class'
&& (($tokenType === T_CLASS || $tokenType === T_INTERFACE || $tokenType === T_TRAIT) && $infos[$infoIndex]['type'] === 'class'
|| ($tokenType === T_FUNCTION && $infos[$infoIndex]['type'] === 'function'))
) {
$infos[$infoIndex]['shortName'] = $tokens[$tokenIndex + 2][1];
Expand Down
14 changes: 14 additions & 0 deletions tests/ZendTest/Code/Scanner/TokenArrayScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public function testScannerReturnsClassNames()
$this->assertContains('ZendTest\Code\TestAsset\FooClass', $classes);
}

/**
* @group gh-4989
*/
public function testScannerReturnsClassNamesForTraits()
{
if (version_compare(PHP_VERSION, '5.4', 'lt')) {
$this->markTestSkipped('Skipping; PHP 5.4 or greater is needed');
}
$tokenScanner = new TokenArrayScanner(token_get_all(file_get_contents((__DIR__ . '/../TestAsset/FooTrait.php'))));
$classes = $tokenScanner->getClassNames();
$this->assertInternalType('array', $classes);
$this->assertContains('ZendTest\Code\TestAsset\FooTrait', $classes);
}

public function testScannerReturnsFunctions()
{
$tokenScanner = new TokenArrayScanner(token_get_all(file_get_contents((__DIR__ . '/../TestAsset/functions.php'))));
Expand Down
17 changes: 17 additions & 0 deletions tests/ZendTest/Code/TestAsset/BarTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Code\TestAsset;

trait BarTrait
{
public function bar()
{
}
}
19 changes: 19 additions & 0 deletions tests/ZendTest/Code/TestAsset/FooTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Code\TestAsset;

trait FooTrait
{
use BarTrait;

public function fooBarBaz()
{
}
}

0 comments on commit d5b2175

Please sign in to comment.