1
0
Fork 0

expand regex and testcases

pull/8082/head
Rob Bast 2019-04-03 11:38:06 +02:00
parent 971528916b
commit 25e3f6d4b9
2 changed files with 63 additions and 30 deletions

View File

@ -162,7 +162,7 @@ class ClassMapGenerator
} }
// strip heredocs/nowdocs // strip heredocs/nowdocs
$contents = preg_replace('{<<<\s*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r|\s*)\\2(?=\r\n|\n|\r|\s|;)}s', 'null', $contents); $contents = preg_replace('{<<<[ \t]*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\s+)\\2(?=\s+|[;,.)])}s', 'null', $contents);
// strip strings // strip strings
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
// strip leading non-php code if needed // strip leading non-php code if needed

View File

@ -7,48 +7,81 @@ namespace Foo;
*/ */
class StripNoise class StripNoise
{ {
public function test() public function test_heredoc()
{ {
return <<<A return <<<HEREDOC
class Fail2 class FailHeredocBasic
{ {
} }
A HEREDOC . <<< WHITESPACE
. <<< AB class FailHeredocWhitespace
class Fail3
{ {
} }
AB WHITESPACE . <<<"DOUBLEQUOTES"
. <<<'TEST' class FailHeredocDoubleQuotes
class Fail4
{ {
} }
TEST DOUBLEQUOTES . <<< "DOUBLEQUOTESTABBED"
. <<< 'ANOTHER' class FailHeredocDoubleQuotesTabbed
class Fail5
{ {
} }
ANOTHER DOUBLEQUOTESTABBED . <<<HEREDOCPHP73
. <<< "ONEMORE" class FailHeredocPHP73
class Fail6
{
}
ONEMORE
. <<<PHP73
class Fail7
{ {
} }
PHP73; HEREDOCPHP73;
} }
public function test2() public function test_nowdoc()
{ {
$class = 'class Fail4 {}'; return <<<'NOWDOC'
class FailNowdocBasic
{
}
NOWDOC . <<< 'WHITESPACE'
class FailNowdocWhitespace
{
}
WHITESPACE . <<< 'NOWDOCTABBED'
class FailNowdocTabbed
{
}
NOWDOCTABBED . <<<'NOWDOCPHP73'
class FailNowdocPHP73
{
}
NOWDOCPHP73;
}
public function test_followed_by_parentheses()
{
return array(<<<PARENTHESES
class FailParentheses
{
}
PARENTHESES);
}
public function test_followed_by_comma()
{
return array(1, 2, <<<COMMA
class FailComma
{
}
COMMA, 3, 4);
}
public function test_followed_by_period()
{
return <<<PERIOD
class FailPeriod
{
}
PERIOD.'?>';
}
public function test_simple_string()
{
return 'class FailSimpleString {}';
} }
} }