@@ -33,6 +33,48 @@ final class GetMetaSingleSniff extends AbstractFunctionParameterSniff {
3333 */
3434 const METRIC_NAME = 'get_*meta() function called with $single parameter ' ;
3535
36+ /**
37+ * Relevant signature structure for generic meta functions.
38+ *
39+ * These functions use 'meta_key' as the parameter name at position 3 and
40+ * 'single' as the parameter name at position 4.
41+ *
42+ * @since 3.3.0
43+ *
44+ * @var array<string, array<string, int|string>>
45+ */
46+ private const GENERIC_META_FUNCTIONS_FORMAT = array (
47+ 'condition ' => array (
48+ 'param_name ' => 'meta_key ' ,
49+ 'position ' => 3 ,
50+ ),
51+ 'recommended ' => array (
52+ 'param_name ' => 'single ' ,
53+ 'position ' => 4 ,
54+ ),
55+ );
56+
57+ /**
58+ * Relevant signature structure for specific meta functions.
59+ *
60+ * These functions use 'key' as the parameter name at position 2 and
61+ * 'single' as the parameter name at position 3.
62+ *
63+ * @since 3.3.0
64+ *
65+ * @var array<string, array<string, int|string>>
66+ */
67+ private const SPECIFIC_META_FUNCTIONS_FORMAT = array (
68+ 'condition ' => array (
69+ 'param_name ' => 'key ' ,
70+ 'position ' => 2 ,
71+ ),
72+ 'recommended ' => array (
73+ 'param_name ' => 'single ' ,
74+ 'position ' => 3 ,
75+ ),
76+ );
77+
3678 /**
3779 * The group name for this group of functions.
3880 *
@@ -45,10 +87,6 @@ final class GetMetaSingleSniff extends AbstractFunctionParameterSniff {
4587 /**
4688 * List of functions this sniff should examine.
4789 *
48- * {@internal Once support for PHP < 5.6 is dropped, it is possible to create two class constants
49- * representing the two different signatures of get meta functions to remove the duplication
50- * of the name and position of the parameters.}
51- *
5290 * @link https://developer.wordpress.org/reference/functions/get_comment_meta/
5391 * @link https://developer.wordpress.org/reference/functions/get_metadata/
5492 * @link https://developer.wordpress.org/reference/functions/get_metadata_default/
@@ -66,86 +104,14 @@ final class GetMetaSingleSniff extends AbstractFunctionParameterSniff {
66104 * the relevant parameters.
67105 */
68106 protected $ target_functions = array (
69- 'get_comment_meta ' => array (
70- 'condition ' => array (
71- 'param_name ' => 'key ' ,
72- 'position ' => 2 ,
73- ),
74- 'recommended ' => array (
75- 'param_name ' => 'single ' ,
76- 'position ' => 3 ,
77- ),
78- ),
79- 'get_metadata ' => array (
80- 'condition ' => array (
81- 'param_name ' => 'meta_key ' ,
82- 'position ' => 3 ,
83- ),
84- 'recommended ' => array (
85- 'param_name ' => 'single ' ,
86- 'position ' => 4 ,
87- ),
88- ),
89- 'get_metadata_default ' => array (
90- 'condition ' => array (
91- 'param_name ' => 'meta_key ' ,
92- 'position ' => 3 ,
93- ),
94- 'recommended ' => array (
95- 'param_name ' => 'single ' ,
96- 'position ' => 4 ,
97- ),
98- ),
99- 'get_metadata_raw ' => array (
100- 'condition ' => array (
101- 'param_name ' => 'meta_key ' ,
102- 'position ' => 3 ,
103- ),
104- 'recommended ' => array (
105- 'param_name ' => 'single ' ,
106- 'position ' => 4 ,
107- ),
108- ),
109- 'get_post_meta ' => array (
110- 'condition ' => array (
111- 'param_name ' => 'key ' ,
112- 'position ' => 2 ,
113- ),
114- 'recommended ' => array (
115- 'param_name ' => 'single ' ,
116- 'position ' => 3 ,
117- ),
118- ),
119- 'get_site_meta ' => array (
120- 'condition ' => array (
121- 'param_name ' => 'key ' ,
122- 'position ' => 2 ,
123- ),
124- 'recommended ' => array (
125- 'param_name ' => 'single ' ,
126- 'position ' => 3 ,
127- ),
128- ),
129- 'get_term_meta ' => array (
130- 'condition ' => array (
131- 'param_name ' => 'key ' ,
132- 'position ' => 2 ,
133- ),
134- 'recommended ' => array (
135- 'param_name ' => 'single ' ,
136- 'position ' => 3 ,
137- ),
138- ),
139- 'get_user_meta ' => array (
140- 'condition ' => array (
141- 'param_name ' => 'key ' ,
142- 'position ' => 2 ,
143- ),
144- 'recommended ' => array (
145- 'param_name ' => 'single ' ,
146- 'position ' => 3 ,
147- ),
148- ),
107+ 'get_comment_meta ' => self ::SPECIFIC_META_FUNCTIONS_FORMAT ,
108+ 'get_metadata ' => self ::GENERIC_META_FUNCTIONS_FORMAT ,
109+ 'get_metadata_default ' => self ::GENERIC_META_FUNCTIONS_FORMAT ,
110+ 'get_metadata_raw ' => self ::GENERIC_META_FUNCTIONS_FORMAT ,
111+ 'get_post_meta ' => self ::SPECIFIC_META_FUNCTIONS_FORMAT ,
112+ 'get_site_meta ' => self ::SPECIFIC_META_FUNCTIONS_FORMAT ,
113+ 'get_term_meta ' => self ::SPECIFIC_META_FUNCTIONS_FORMAT ,
114+ 'get_user_meta ' => self ::SPECIFIC_META_FUNCTIONS_FORMAT ,
149115 );
150116
151117 /**
0 commit comments