-
Notifications
You must be signed in to change notification settings - Fork 19
Conversation
eaea370
to
484e5c8
Compare
@localheinz Please rebase to resolve conflicts, which will trigger a new build as well. Thanks! |
c3b7e29
to
2058712
Compare
Sorted! |
And thanks a lot for reviewing these on such a short notice, I appreciate it! Since https://github.com/zendframework/modules.zendframework.com (where I am a maintainer) is kind of dead, I wouldn't mind getting involved as a maintainer with a different Zend project, please let me know if there's interest! |
|
||
// ignore anonymous classes on PHP 7.1 and greater | ||
if (PHP_VERSION_ID >= 70100 | ||
&& $i > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, should this be $i > 1
, actually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You tell me; haven't played with tokenizing anonymous classes yet. :) What happens in the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted a few changes. Additionally, in the files changed (but not introduced), update the copyright in the file-level docblock to reference 2017.
Thanks!
|
||
// ignore anonymous classes on PHP 7.1 and greater | ||
if (PHP_VERSION_ID >= 70100 | ||
&& $i > 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You tell me; haven't played with tokenizing anonymous classes yet. :) What happens in the tests?
&& \is_array($tokens[$i - 1]) | ||
&& $tokens[$i - 1][0] === T_WHITESPACE | ||
&& \is_array($tokens[$i - 2]) | ||
&& $tokens[$i - 2][0] === T_NEW |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use yoda conditions for the constant comparisons here.
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three changes:
- Reference the zend-file repository, using https.
- Since this file is just being introduced, change the copyright date to simply
2017
. - Point to https://github.com/zendframework/zend-file/blob/master/LICENSE.md for the license.
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same notes on this docblock as for the previous.
ee58139
to
b91ff16
Compare
|
||
// ignore anonymous classes on PHP 7.1 and greater | ||
if (PHP_VERSION_ID >= 70100 | ||
&& $i >= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified this condition
-&& $i > 2
+&& $i >+ 2
as the index doesn't need to be greater than 2, but at least 2 (since we try to access the element at $i - 2
).
Will merge once I verify the build with Travis. Currently their running on a bit of a delay, due to the queue. |
Thanks a ton, @weierophinney! |
@localheinz Already seeing errors on all jobs run so far: https://travis-ci.org/zendframework/zend-file/builds/190986651 |
|
||
namespace ZendTest\File\TestAsset\Anonymous; | ||
|
||
$anonymous = new class extends \stdClass { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is, on the other hand, should the ClassFileLocator
actually accept a PHP file that doesn't contain any classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect that it would ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify: the intent of the class is to find files that declare named classes. It was originally developed as a utility for creating class maps for autoloading. Anonymous classes, as they are not named, would fall outside that criteria.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will update later, @weierophinney!
a0087cb
to
a2cec18
Compare
Amended the previous commit: diff --git a/src/ClassFileLocator.php b/src/ClassFileLocator.php
index 82619a2..767fee4 100644
--- a/src/ClassFileLocator.php
+++ b/src/ClassFileLocator.php
@@ -124,8 +124,7 @@ class ClassFileLocator extends FilterIterator
}
// ignore anonymous classes on PHP 7.1 and greater
- if (PHP_VERSION_ID >= 70100
- && $i >= 2
+ if ($i >= 2
&& \is_array($tokens[$i - 1])
&& T_WHITESPACE === $tokens[$i - 1][0]
&& \is_array($tokens[$i - 2]) 👍 |
@@ -122,6 +122,17 @@ public function accept() | |||
if ($i > 0 && is_array($tokens[$i - 1]) && $tokens[$i - 1][0] === T_DOUBLE_COLON) { | |||
break; | |||
} | |||
|
|||
// ignore anonymous classes on PHP 7.1 and greater | |||
if (&& $i >= 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um... &&
to start the conditional...? Also, will $i >= 2
only ever happen on PHP 7.1, or will this work on any version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, hehe!
Well, I guess trying to run
$tokens = token_get_all($contents);
when $contents
contains usage of anonymous classes will already fail on a PHP version less than PHP 7.1, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, no, works fine on all PHP versions, see https://3v4l.org/0enag!
c359f7f
to
8651341
Compare
Fix: Ignore anonymous classes
Forward port #34 Conflicts: CHANGELOG.md
Thanks a ton, @weierophinney! |
This PR
Follows #29.