diff --git a/lib/class-method-call-reflector.php b/lib/class-method-call-reflector.php index 9ad6bd20..071f1004 100644 --- a/lib/class-method-call-reflector.php +++ b/lib/class-method-call-reflector.php @@ -89,35 +89,37 @@ public function isStatic() { */ protected function _getClassMapping() { + // Keys are receiver expressions as printed by the pretty printer, so + // global variables keep their `$` sigil. // List of global use generated using following command: - // ack "global \\\$[^;]+;" --no-filename | tr -d '\t' | sort | uniq | sed "s/global //g" | sed "s/, /,/g" | tr , '\n' | sed "s/;//g" | sort | uniq | sed "s/\\\$//g" | sed "s/[^ ][^ ]*/'&' => ''/g" + // ack "global \\\$[^;]+;" --no-filename | tr -d '\t' | sort | uniq | sed "s/global //g" | sed "s/, /,/g" | tr , '\n' | sed "s/;//g" | sort | uniq | sed "s/[^ ][^ ]*/'&' => ''/g" // There is probably an easier way, there are currently no globals that are classes starting with an underscore $wp_globals = array( - 'authordata' => 'WP_User', - 'custom_background' => 'Custom_Background', - 'custom_image_header' => 'Custom_Image_Header', - 'phpmailer' => 'PHPMailer', - 'post' => 'WP_Post', - 'userdata' => 'WP_User', // This can also be stdClass, but you can't call methods on an stdClass - 'wp' => 'WP', - 'wp_admin_bar' => 'WP_Admin_Bar', - 'wp_customize' => 'WP_Customize_Manager', - 'wp_embed' => 'WP_Embed', - 'wp_filesystem' => 'WP_Filesystem', - 'wp_hasher' => 'PasswordHash', // This can be overridden by plugins, for core assume this is ours - 'wp_json' => 'Services_JSON', - 'wp_list_table' => 'WP_List_Table', // This one differs because there are a lot of different List Tables, assume they all only overwrite existing functions on WP_List_Table - 'wp_locale' => 'WP_Locale', - 'wp_object_cache' => 'WP_Object_Cache', - 'wp_query' => 'WP_Query', - 'wp_rewrite' => 'WP_Rewrite', - 'wp_roles' => 'WP_Roles', - 'wp_scripts' => 'WP_Scripts', - 'wp_styles' => 'WP_Styles', - 'wp_the_query' => 'WP_Query', - 'wp_widget_factory' => 'WP_Widget_Factory', - 'wp_xmlrpc_server' => 'wp_xmlrpc_server', // This can be overridden by plugins, for core assume this is ours - 'wpdb' => 'wpdb', + '$authordata' => 'WP_User', + '$custom_background' => 'Custom_Background', + '$custom_image_header' => 'Custom_Image_Header', + '$phpmailer' => 'PHPMailer', + '$post' => 'WP_Post', + '$userdata' => 'WP_User', // This can also be stdClass, but you can't call methods on an stdClass + '$wp' => 'WP', + '$wp_admin_bar' => 'WP_Admin_Bar', + '$wp_customize' => 'WP_Customize_Manager', + '$wp_embed' => 'WP_Embed', + '$wp_filesystem' => 'WP_Filesystem', + '$wp_hasher' => 'PasswordHash', // This can be overridden by plugins, for core assume this is ours + '$wp_json' => 'Services_JSON', + '$wp_list_table' => 'WP_List_Table', // This one differs because there are a lot of different List Tables, assume they all only overwrite existing functions on WP_List_Table + '$wp_locale' => 'WP_Locale', + '$wp_object_cache' => 'WP_Object_Cache', + '$wp_query' => 'WP_Query', + '$wp_rewrite' => 'WP_Rewrite', + '$wp_roles' => 'WP_Roles', + '$wp_scripts' => 'WP_Scripts', + '$wp_styles' => 'WP_Styles', + '$wp_the_query' => 'WP_Query', + '$wp_widget_factory' => 'WP_Widget_Factory', + '$wp_xmlrpc_server' => 'wp_xmlrpc_server', // This can be overridden by plugins, for core assume this is ours + '$wpdb' => 'wpdb', ); $wp_functions = array( diff --git a/tests/phpunit/tests/export/uses/methods.inc b/tests/phpunit/tests/export/uses/methods.inc index e7a16457..a1fd1b35 100644 --- a/tests/phpunit/tests/export/uses/methods.inc +++ b/tests/phpunit/tests/export/uses/methods.inc @@ -19,3 +19,5 @@ class My_Class extends Parent_Class { parent::do_parental_stuff(); } } + +$wp_the_query->get( 'paged' ); diff --git a/tests/phpunit/tests/export/uses/methods.php b/tests/phpunit/tests/export/uses/methods.php index aad38ff5..979a11f6 100644 --- a/tests/phpunit/tests/export/uses/methods.php +++ b/tests/phpunit/tests/export/uses/methods.php @@ -84,7 +84,17 @@ public function test_instance_methods() { 'name' => 'update', 'line' => 5, 'end_line' => 5, - 'class' => '$wpdb', + 'class' => 'wpdb', + 'static' => false, + ) + ); + + $this->assertFileUsesMethod( + array( + 'name' => 'get', + 'line' => 23, + 'end_line' => 23, + 'class' => 'WP_Query', 'static' => false, ) );