[wp-trac] [WordPress Trac] #54177: Add visibility to test class methods

WordPress Trac noreply at wordpress.org
Fri Sep 24 06:39:08 UTC 2021


#54177: Add visibility to test class methods
------------------------------+-----------------------------
 Reporter:  costdev           |      Owner:  (none)
     Type:  enhancement       |     Status:  new
 Priority:  normal            |  Milestone:  Awaiting Review
Component:  Build/Test Tools  |    Version:
 Severity:  normal            |   Keywords:
  Focuses:  coding-standards  |
------------------------------+-----------------------------
 There are many tests that do not identify their visibility.

 This ticket proposes to add `public` visibility to all test classes except
 those that begin with an underscore, suggesting `private/protected`
 visibility. This ticket proposes that these methods are given `private`
 visibility.

 See results below.


 ----


 **Public Visibility: Attempt 1**
 {{{

 /**
  * Methods that:
  *
  * 1. Begin with the start of a line, followed by one {TAB} character;
  * 2. may or may not be static;
  * 3. may or may not be passed by reference;
  * 4. do not have a leading underscore, suggesting public visibility.
  *
  * N.B. These are given PUBLIC visibility.
  */

 Find:    ^(\t)(static )?(function )(&)?([^_])
 Replace: $1$2public $3$4$5
 Results: 3119 results in 314 files.
 Gotchas: Many. Too many.

 }}}

 **Public Visibility: Revision 1**

 {{{

 /**
  * Methods that:
  *
  * 1. Begin with the start of a line, followed by one or more {TAB}
 characters;
  * 2. may or may not be static;
  * 3. may or may not be passed by reference;
  * 4. do not have a leading underscore, suggesting public visibility;
  * 5. match the prefix of test class methods (manual review of 3159 names
 to get prefixes).
  *
  * N.B. These are given PUBLIC visibility.
  */

 Find:    ^(\t{1,})(static )?(function
 )(&)?([^_])(est|ata|ction|ilter|et|ear|lean|pply|init|s_unique|pload_dir|p_dropdown|p_mail|ub_reg|etrieve|ender|andle|ynamic|nstantiate|ate_validate_length|anitize|apture|eturn|o_customize|ustom|emove|verride|dd_custom|o_atom|o_rss|estable|ingle|upported|nvalid|nsupported|ntities|ocales|reaks|tf8|ig5|ncrement|dd_query_arg|arse|p_translate|ock_|pTear|he_posts|re_get|lain_|retty_|mpty_|upports|uthorless|o_example_shortcode|rant_unfiltered|evoke_unfiltered|isable)
 Replace: $1$2public $3$4$5$6
 Results: 3244 results in 328 files.
 Gotchas: (nested functions)

 - get_template_ids
 - filter_allowed_block_types_my_editor
 - filter_block_categories_my_editor
 - filter_block_editor_settings_my_editor
 - filter_remove_preload_paths
 - filter_add_preload_paths
 - find_and_normalize_template_by_id
 - Numerous nested static anonymous functions, always indented by at least
 3 {TAB} characters.

 }}}

 **Public Visibility: Revision 2**

 {{{

 /**
  * Methods that:
  *
  * 1. Begin with the start of a line, followed by one or two {TAB}
 characters (to exclude the static anonymous gotchas);
  * 2. may or may not be static;
  * 3. may or may not be passed by reference;
  * 4. do not have a leading underscore, suggesting public visibility;
  * 5. match the names of identified named gotchas.
  *
  * N.B. These are given PUBLIC visibility.
  */

 Find:    ^(\t{1,2})(static )?(function
 )(&)?([^_])(?!et_template_ids|ilter_allowed_block_types_my_editor|ilter_block_categories_my_editor|ilter_block_editor_settings_my_editor|ilter_remove_preload_paths|ilter_add_preload_paths|ind_and_normalize_template_by_id)
 Replace: $1$2public $3$4$5
 Results: 3252 results in 328 files.
 Gotchas: No gotchas identified.

 }}}


 ----


 **Private Visibility: Attempt 1**
 {{{

 /**
  * Methods that:
  *
  * 1. begin with the start of a line, followed by one or two or more {TAB}
 characters.
  * 2. may or may not be static;
  * 3. may or may not be passed by reference;
  * 4. have a leading underscore, suggesting private/protected visibility.
  *
  * N.B. These are given PRIVATE visibility.
  */

 Find:    ^(\t{1,})(static )?(function )(&)?([_])
 Replace: $1$2private $3$4$5
 Results: 97 results in 40 files.
 Gotchas: No gotchas identified.

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54177>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list