Anonymize some callbacks

This commit is contained in:
Nikita Popov 2015-05-02 22:35:15 +02:00
parent 9d42e4a2e2
commit 5d1e3be7d4
2 changed files with 14 additions and 18 deletions

View File

@ -78,23 +78,21 @@ class String_ extends Scalar
return preg_replace_callback(
'~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3})~',
array(__CLASS__, 'parseCallback'),
function($matches) {
$str = $matches[1];
if (isset(self::$replacements[$str])) {
return self::$replacements[$str];
} elseif ('x' === $str[0] || 'X' === $str[0]) {
return chr(hexdec($str));
} else {
return chr(octdec($str));
}
},
$str
);
}
private static function parseCallback($matches) {
$str = $matches[1];
if (isset(self::$replacements[$str])) {
return self::$replacements[$str];
} elseif ('x' === $str[0] || 'X' === $str[0]) {
return chr(hexdec($str));
} else {
return chr(octdec($str));
}
}
/**
* @internal
*

View File

@ -17,7 +17,9 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
// evaluate @@{expr}@@ expressions
$fileContents = preg_replace_callback(
'/@@\{(.*?)\}@@/',
array($this, 'evalCallback'),
function($matches) {
return eval('return ' . $matches[1] . ';');
},
$fileContents
);
@ -36,10 +38,6 @@ abstract class CodeTestAbstract extends \PHPUnit_Framework_TestCase
return $tests;
}
protected function evalCallback($matches) {
return eval('return ' . $matches[1] . ';');
}
protected function canonicalize($str) {
// trim from both sides
$str = trim($str);