bac91b42 | 11-Nov-2017 |
Maks Rafalko |
Correctly determine Type of Node when PHP-Parser's namespaces are prefixed Hi there, I'm working on mutation testing framework ([Infection](https://github.com/infection/infection/))
Correctly determine Type of Node when PHP-Parser's namespaces are prefixed 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`
show more ...
|