Skip to content

Commit 93c1c8b

Browse files
authored
Various PHPStan Fixes (#88)
* Fixes #51 * Fixes #53 * Fixes #54 * Fixes #56 * Fixes #57 * Fixes #58 * Fixes #60. Fixes #61 * Fixes #62 * See #63
1 parent 0d77dff commit 93c1c8b

12 files changed

+19
-88
lines changed

bin/baseline.neon

-72
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Action callback returns array but should not return anything\.$#'
5-
identifier: return.void
6-
count: 1
7-
path: ../includes/acf-bidirectional-functions.php
8-
93
-
104
message: '#^@param array \$sub_field does not accept actual type of parameter\: int\|false\.$#'
115
identifier: parameter.phpDocType
@@ -42,18 +36,6 @@ parameters:
4236
count: 2
4337
path: ../includes/acf-field-functions.php
4438

45-
-
46-
message: '#^Function acf_set_filters\(\) should return array but return statement is missing\.$#'
47-
identifier: return.missing
48-
count: 1
49-
path: ../includes/acf-helper-functions.php
50-
51-
-
52-
message: '#^Action callback returns mixed but should not return anything\.$#'
53-
identifier: return.void
54-
count: 1
55-
path: ../includes/acf-hook-functions.php
56-
5739
-
5840
message: '#^Function acf_checkbox_input\(\) should return string but return statement is missing\.$#'
5941
identifier: return.missing
@@ -96,60 +78,6 @@ parameters:
9678
count: 1
9779
path: ../includes/acf-input-functions.php
9880

99-
-
100-
message: '#^Result of function acf_add_validation_error \(void\) is used\.$#'
101-
identifier: function.void
102-
count: 1
103-
path: ../includes/acf-internal-post-type-functions.php
104-
105-
-
106-
message: '#^Result of function acf_copy_metadata \(void\) is used\.$#'
107-
identifier: function.void
108-
count: 1
109-
path: ../includes/acf-meta-functions.php
110-
111-
-
112-
message: '#^One or more @param tags has an invalid name or invalid syntax\.$#'
113-
identifier: phpDoc.parseError
114-
count: 1
115-
path: ../includes/acf-user-functions.php
116-
117-
-
118-
message: '#^Action callback returns string but should not return anything\.$#'
119-
identifier: return.void
120-
count: 1
121-
path: ../includes/admin/admin-internal-post-type-list.php
122-
123-
-
124-
message: '#^Action callback returns string but should not return anything\.$#'
125-
identifier: return.void
126-
count: 1
127-
path: ../includes/admin/admin-internal-post-type.php
128-
129-
-
130-
message: '#^Filter callback return statement is missing\.$#'
131-
identifier: return.missing
132-
count: 1
133-
path: ../includes/admin/admin-internal-post-type.php
134-
135-
-
136-
message: '#^Action callback returns string but should not return anything\.$#'
137-
identifier: return.void
138-
count: 1
139-
path: ../includes/admin/admin-tools.php
140-
141-
-
142-
message: '#^Action callback returns string but should not return anything\.$#'
143-
identifier: return.void
144-
count: 2
145-
path: ../includes/admin/admin-upgrade.php
146-
147-
-
148-
message: '#^Action callback returns string but should not return anything\.$#'
149-
identifier: return.void
150-
count: 1
151-
path: ../includes/admin/admin.php
152-
15381
-
15482
message: '#^Access to an undefined property ACF_Admin_Field_Groups\:\:\$not_found_label\.$#'
15583
identifier: property.notFound

includes/acf-bidirectional-functions.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* @param integer|string $post_id The ACF encoded origin post, user or term ID.
1616
* @param array $field The field being updated on the origin post, user or term ID.
1717
* @param string|false $target_prefix The ACF prefix for a post, user or term ID required for the update_field call for this field type.
18+
*
19+
* @return void
1820
*/
1921
function acf_update_bidirectional_values( $target_item_ids, $post_id, $field, $target_prefix = false ) {
2022

@@ -201,14 +203,16 @@ function ( $field_group ) {
201203
return $results;
202204
}
203205

204-
add_action( 'acf/fields/select/query/key=_acf_bidirectional_target', 'acf_build_bidirectional_relationship_field_target_args', 10, 2 );
206+
add_filter( 'acf/fields/select/query/key=_acf_bidirectional_target', 'acf_build_bidirectional_relationship_field_target_args', 10, 2 );
205207

206208
/**
207209
* Renders the field settings required for bidirectional fields
208210
*
209211
* @since ACF 6.2
210212
*
211213
* @param array $field The field object passed into field setting functions.
214+
*
215+
* @return void
212216
*/
213217
function acf_render_bidirectional_field_settings( $field ) {
214218
if ( ! acf_get_setting( 'enable_bidirection' ) ) {

includes/acf-helper-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function acf_get_filters() {
201201
* @since ACF 5.4.0
202202
*
203203
* @param array $filters An Array of modifiers.
204-
* @return array
204+
* @return void
205205
*/
206206
function acf_set_filters( $filters = array() ) {
207207
acf_get_store( 'filters' )->set( $filters );

includes/acf-hook-functions.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function acf_add_action_variations( $action = '', $variations = array(), $index
6060

6161
// Add generic handler.
6262
// Use a priority of 10, and accepted args of 10 (ignored by WP).
63+
// @phpstan-ignore return.void
6364
add_action( $action, '_acf_apply_hook_variations', 10, 10 );
6465
}
6566

@@ -105,7 +106,7 @@ function _acf_apply_hook_variations() {
105106
}
106107

107108
// Apply filters.
108-
if ( $type === 'filter' ) {
109+
if ( 'filters' === $type ) {
109110
$args[0] = apply_filters_ref_array( "$filter/$variation=$value", $args );
110111

111112
// Or do action.

includes/acf-internal-post-type-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ function acf_add_internal_post_type_validation_error( $name, $message = '', $pos
642642
$name = "{$input_prefix}[$name]";
643643
}
644644

645-
return acf_add_validation_error( $name, $message );
645+
acf_add_validation_error( $name, $message );
646646
}
647647

648648
/**

includes/acf-meta-functions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function acf_copy_metadata( $from_post_id = 0, $to_post_id = 0 ) {
284284
* @return void
285285
*/
286286
function acf_copy_postmeta( $from_post_id = 0, $to_post_id = 0 ) {
287-
return acf_copy_metadata( $from_post_id, $to_post_id );
287+
acf_copy_metadata( $from_post_id, $to_post_id );
288288
}
289289

290290
/**

includes/acf-user-functions.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ function acf_get_user_role_labels( $roles = array() ) {
9292
}
9393

9494
/**
95-
* acf_allow_unfiltered_html
96-
*
9795
* Returns true if the current user is allowed to save unfiltered HTML.
9896
*
99-
* @date 9/1/19
10097
* @since ACF 5.7.10
10198
*
10299
* @return boolean
@@ -112,7 +109,7 @@ function acf_allow_unfiltered_html() {
112109
* @date 9/1/19
113110
* @since ACF 5.7.10
114111
*
115-
* @param bool allow_unfiltered_html The result.
112+
* @param bool $allow_unfiltered_html Can the current user save unfiltered HTML.
116113
*/
117114
return apply_filters( 'acf/allow_unfiltered_html', $allow_unfiltered_html );
118115
}

includes/admin/admin-internal-post-type-list.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function current_screen() {
146146

147147
// Add hooks.
148148
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
149-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
149+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
150150
add_filter( "views_edit-{$this->post_type}", array( $this, 'admin_table_views' ), 10, 1 );
151151
add_filter( "manage_{$this->post_type}_posts_columns", array( $this, 'admin_table_columns' ), 10, 1 );
152152
add_action( "manage_{$this->post_type}_posts_custom_column", array( $this, 'admin_table_columns_html' ), 10, 2 );

includes/admin/admin-internal-post-type.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function current_screen() {
9191
acf_disable_filters();
9292
acf_enqueue_scripts();
9393

94-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
94+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
9595
add_action( 'acf/input/admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
9696
add_action( 'acf/input/admin_head', array( $this, 'admin_head' ) );
9797
add_action( 'acf/input/form_data', array( $this, 'form_data' ) );
@@ -164,10 +164,11 @@ public function admin_footer() {
164164
* @since ACF 5.3.8
165165
*
166166
* @param array $l10n The array of translated strings.
167-
* @return void
167+
* @return mixed
168168
*/
169169
public function admin_l10n( $l10n ) {
170170
// Override as necessary.
171+
return $l10n;
171172
}
172173

173174
/**

includes/admin/admin-tools.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function admin_menu() {
122122
*/
123123
public function load() {
124124

125-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
125+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
126126

127127
// disable filters (default to raw data)
128128
acf_disable_filters();

includes/admin/admin-upgrade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function check_for_network_upgrades() {
174174
*/
175175
public function admin_load() {
176176

177-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
177+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
178178

179179
// remove prompt
180180
remove_action( 'admin_notices', array( $this, 'admin_notices' ) );
@@ -195,7 +195,7 @@ public function admin_load() {
195195
*/
196196
public function network_admin_load() {
197197

198-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
198+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
199199

200200
// remove prompt
201201
remove_action( 'network_admin_notices', array( $this, 'network_admin_notices' ) );

includes/admin/admin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ACF_Admin {
1717
public function __construct() {
1818
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
1919
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
20-
add_action( 'admin_body_class', array( $this, 'admin_body_class' ) );
20+
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
2121
add_action( 'current_screen', array( $this, 'current_screen' ) );
2222
add_action( 'admin_notices', array( $this, 'maybe_show_escaped_html_notice' ) );
2323
add_action( 'admin_init', array( $this, 'dismiss_escaped_html_notice' ) );

0 commit comments

Comments
 (0)