php-scoper
php-scoper copied to clipboard
Namespace being added to a numbered string
Came across this line:
$body = RegEx::replace('...(some).*?(regex)...', '\\1\\2', $body);
Which got replaced with:
$body = \MyPhpScoperPrefix\RegEx::replace('...(some).*?(regex)...', '\MyPhpScoperPrefix\\1\\2', $body);
I worked around this issue by adding this to my scoper.inc.php:
'exclude-namespaces' => [
...
'1'
],
But it is of course a bug.
Unfortunately it is expected to some degree. It is hard to detect what string can and cannot be scoped so there is bound to be cases of strings incorrectly scoped and others incorrectly not scoped. You will have to fix this via patchers.
This peculiar case however does not make much sense indeed, as 1\2 cannot be a class name.
Exactly, as classnames/namespaces cannot start with a number. So probably a good idea to adjust the regex (I assume that is being used) to find the namespaces.
Probably in XmlScoper, the regex parts [\p{L}_\d]+ should be replaced with [\p{L}_][\p{L}_\d]*.
And [^\\\\]+ with [\p{L}][^\\\\]*.
Seems to be working great. Thanks!