Skip to content

Commit

Permalink
Fix whitespace being reported as method caller
Browse files Browse the repository at this point in the history
When a method call was wrapped to another line, the whitespace in front of it would be reported as the caller, instead of the correct variable or `(unknown)`.

Fixes #31

(cherry picked from commit 5faaf63)
  • Loading branch information
JDGrimes committed Nov 2, 2016
1 parent eb24196 commit b17f374
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions tests/data/class-method-names.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ function inner_func( _debug_ ) {}

get_some_class()->method( _debug_ );

wordpoints_component( $var )
->get_sub_app( $var )
->get_sub_app( _debug_ );

$var
->wrap( _debug_ );

interface ParentI {
public function parent_method( $var _debug_ );
}
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/class-method-names.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function test_class_method_names() {
'$wpdb->query',
'WP_Query::__construct',
'(unknown)->method',
'(unknown)->get_sub_app',
'$var->wrap',
'ParentI::parent_method',
'ChildI::ignored',
'Implementor::parent_method',
Expand Down
15 changes: 12 additions & 3 deletions wp-l10n-validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,17 @@ private function _parse_string( $content ) {

case '::':
case '->':
if ( isset( $tokens[ $index - 2 ][1] ) ) {
switch ( $tokens[ $index - 2 ][1] ) {
$caller_index = $index - 2;

if (
isset( $tokens[ $caller_index ][0] )
&& T_WHITESPACE === $tokens[ $caller_index ][0]
) {
$caller_index -= 1;
}

if ( isset( $tokens[ $caller_index ][1] ) ) {
switch ( $tokens[ $caller_index ][1] ) {

case 'self':
case '$this':
Expand All @@ -1055,7 +1064,7 @@ private function _parse_string( $content ) {
// fallthru

default:
$full_function = $tokens[ $index - 2 ][1] . $tokens[ $index - 1 ][1] . $full_function;
$full_function = $tokens[ $caller_index ][1] . $tokens[ $index - 1 ][1] . $full_function;
}

} else {
Expand Down

0 comments on commit b17f374

Please sign in to comment.