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
$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
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
// strip leading non-php code if needed

View File

@ -7,48 +7,81 @@ namespace Foo;
*/
class StripNoise
{
public function test()
public function test_heredoc()
{
return <<<A
class Fail2
return <<<HEREDOC
class FailHeredocBasic
{
}
A
. <<< AB
class Fail3
HEREDOC . <<< WHITESPACE
class FailHeredocWhitespace
{
}
AB
. <<<'TEST'
class Fail4
WHITESPACE . <<<"DOUBLEQUOTES"
class FailHeredocDoubleQuotes
{
}
TEST
. <<< 'ANOTHER'
class Fail5
DOUBLEQUOTES . <<< "DOUBLEQUOTESTABBED"
class FailHeredocDoubleQuotesTabbed
{
}
ANOTHER
. <<< "ONEMORE"
class Fail6
{
}
ONEMORE
. <<<PHP73
class Fail7
DOUBLEQUOTESTABBED . <<<HEREDOCPHP73
class FailHeredocPHP73
{
}
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 {}';
}
}