Correctly determine Type of Node when PHP-Parser's namespaces are prefixed#441
Closed
maks-rafalko wants to merge 1 commit intonikic:masterfrom
maks-rafalko:patch-2
Closed
Correctly determine Type of Node when PHP-Parser's namespaces are prefixed#441maks-rafalko wants to merge 1 commit intonikic:masterfrom maks-rafalko:patch-2
maks-rafalko wants to merge 1 commit intonikic:masterfrom
maks-rafalko:patch-2
Conversation
…fixed Hi there, I'm working on mutation testing framework ([Infection](https://github.com/infection/infection/)) that is distributed as a PHAR. One of this goal is to run target project's test suite against mutated code. Since we use reflection and load project's autoloader, we want to avoid potential conflicts between vendor files of Infection itself and the target project. To avoid this issue, there is a project calld [PHP-Scoper](https://github.com/humbug/php-scoper). What it does is it prefixes all the namespaces of the library (including vendor folder) with some character(s), for example namespace `Infection\Mutator\PublicVisibility` is transformed to `ScoperAbc123\Infection\Mutant\PublicVisibility`. But since it also prefixes vendor folder, PHP-Parser's classes are prefixed as well and `NodeAbstract::getType()` after this prefixing works incorrectly. There is a hardcoded number `15` which means to remove `'PhpParser\Node'` (length=15) substring from the FQCN. Code: ```php // PHPParser\Node\Stmt\Declare_ -> Stmt_Declare return strtr(substr(rtrim(get_class($this), '_'), 15), '\\', '_'); ``` What I suggest is a little be more dynamic solution, to correctly extract class name (type) from the ***prefixed*** FQCL: `ScoperAbc123\PHPParser\Node\Stmt\Declare_` -> `Stmt_Declare`
6 tasks
Owner
Contributor
Author
|
Great, thank you. Do you plan to release a new tag for 3.x? |
Contributor
|
@borNfreee you may also ran into the issue with the Lexer cf. https://github.com/humbug/php-scoper/blob/master/scoper.inc.php#L48. It would be great to fix it here at the core rather than those ugly brittle patches |
nikic
added a commit
that referenced
this pull request
Nov 13, 2017
Owner
|
@theofidry Done with 94ca9a7. |
Contributor
|
Awesome, thanks :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi there,
I'm working on mutation testing framework (Infection) that is distributed as a PHAR. One of its goal is to run target project's test suite against mutated code. Since we use reflection and load project's autoloader, we want to avoid potential conflicts between vendor files of Infection itself and the target project.
To avoid this issue, there is a project called PHP-Scoper. What it does is it prefixes all the namespaces of the library (including vendor folder) with some character(s), for example namespace
Infection\Mutator\PublicVisibilityis transformed toScoperAbc123\Infection\Mutant\PublicVisibility.But since it also prefixes vendor folder, PHP-Parser's classes are prefixed as well and
NodeAbstract::getType()after this prefixing works incorrectly.There is a hardcoded number
15which means to remove'PhpParser\Node'(length=15) substring from the FQCN.Code:
What I suggest is a little bit more dynamic solution, to correctly extract class name (type) from the prefixed FQCN:
ScoperAbc123\PHPParser\Node\Stmt\Declare_->Stmt_Declare