Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Zend-Code] Find php 5.4 traits with TokenArrayScanner #4989

Closed
wants to merge 3 commits into from

3 participants

@danez

Added T_TRAIT next to T_CLASS and T_INTERFACE.

For php 5.3 T_TRAIT gets defined to not get any errors.

@weierophinney

Please add a unit test for this as well -- and thanks!

danez added some commits
@danez danez Added test for issue #4989 22db9a5
@danez danez Find traits with TokenArrayScanner
Added T_TRAIT next to T_CLASS and T_INTERFACE.

For php 5.3 T_TRAIT gets defined to not get any errors.
be3f9b2
@danez

Added test before fixing issue

@danez

composer on travis not working -> failed

@Thinkscape

@Danez Try waiting a few hours and then closing an re-opening the PR.

@danez

Ok i'll try that

@danez danez closed this
@danez danez reopened this
@danez danez closed this
@danez danez reopened this
@danez

Thanks for the tip.

@weierophinney

Merged to develop for release with 2.3.0.

@danez danez deleted the unknown repository branch
@basz basz referenced this pull request from a commit
@basz basz Merge branch 'develop' of git://github.com/zendframework/zf2
# By Matthew Weier O'Phinney (7) and others
# Via Matthew Weier O'Phinney (63) and others
* 'develop' of git://github.com/zendframework/zf2: (40 commits)
  Fix tests for php <5.4
  Find traits with TokenArrayScanner
  Added test for issue #4989
  Fixed failing tests
  Renamed interface and extract HydrationInterface
  [#4979] CS fixes
  [#4969] CS fixes
  [#4931] CS fixes
  [#4912] Re-add removed method
  CS fixes
  Revert "Revert "Merge branch 'superdweebie-rand-bugfix'""
  Fix CS
  Correction for inverted version checks
  change of version checks to use PHP_VERSION_ID constant.
  Aligned method naming to zf style
  Fixed method names
  Zend\Navigation currently uses only one text domain for translating page labels. This commit adds the new option key "textdomain" to Navigation and its (translatable) view helpers. If the option is present, it is used during translation. If the key is not present, the old behavior is applied.
  Added unit test for should not convert to array recursively if model is traversable
  PartialLoop helper: prevent convert traversable model to array recursively
  Add test
  ...
35d0648
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@weierophinney weierophinney referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 21, 2013
  1. @danez

    Added test for issue #4989

    danez authored
  2. @danez

    Find traits with TokenArrayScanner

    danez authored danez committed
    Added T_TRAIT next to T_CLASS and T_INTERFACE.
    
    For php 5.3 T_TRAIT gets defined to not get any errors.
  3. @danez

    Fix tests for php <5.4

    danez authored
This page is out of date. Refresh to see the latest.
View
10 library/Zend/Code/Scanner/TokenArrayScanner.php
@@ -299,6 +299,13 @@ protected function scan()
}
/**
+ * Define PHP 5.4 'trait' token constant.
+ */
+ if (!defined('T_TRAIT')) {
+ define('T_TRAIT', 42001);
+ }
+
+ /**
* Variables & Setup
*/
@@ -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',
@@ -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];
View
14 tests/ZendTest/Code/Scanner/TokenArrayScannerTest.php
@@ -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'))));
View
17 tests/ZendTest/Code/TestAsset/BarTrait.php
@@ -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()
+ {
+ }
+}
View
19 tests/ZendTest/Code/TestAsset/FooTrait.php
@@ -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()
+ {
+ }
+}
Something went wrong with that request. Please try again.