Skip to content

Commit 61d10a8

Browse files
authored
Various PHPCS updates (#13)
* PHPCS for root dir files * PHPCS (mostly) for includes/admin/*.php files * PHPCS: remove all instances of @param void * PHPCS: A few additional files
1 parent 4a498cd commit 61d10a8

File tree

60 files changed

+263
-337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+263
-337
lines changed

.phpcs.xml.dist

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<!-- Exclude package files -->
88
<exclude-pattern>/vendor/*</exclude-pattern>
99
<exclude-pattern>/node_modules/*</exclude-pattern>
10+
<exclude-pattern>/lang/*</exclude-pattern>
1011

1112
<!-- Confirm PHP compat. -->
1213
<config name="testVersion" value="7.4-"/>
@@ -15,7 +16,19 @@
1516
<!-- Display sniff code -->
1617
<arg value="s"/>
1718

18-
<rule ref="WordPress" phpcbf-only="true" />
19+
<rule ref="WordPress">
20+
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" /> <!-- 'acf/hookname' is used throughout. -->
21+
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" /> <!-- This is trivial and not really useful today. -->
22+
<exclude name="WordPress.Files.FileName.InvalidClassFileName" /> <!-- Refactoring of this scale is not in scope yet.-->
23+
</rule>
24+
<rule ref="WordPress.Security.EscapeOutput">
25+
<properties>
26+
<property name="customEscapingFunctions" type="array">
27+
<element value="acf_esc_attrs" /> <!-- This function takes an associated array and escapes both the attr title and attr value. -->
28+
<element value="acf_esc_html" />
29+
</property>
30+
</properties>
31+
</rule>
1932
<rule ref="WordPress.WP.I18n">
2033
<properties>
2134
<property name="text_domain" type="array">

acf.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* This file is for the converting of sites from acf.php to secure-custom-fields.php as the main plugin file.
44
*
55
* Under this slug, acf.php would have been the main plugin file in < 6.4.0-beta4.
6+
*
7+
* @package wordpress/secure-custom-fields
68
*/
79

8-
// Exit if accessed directly
10+
// Exit if accessed directly.
911
if ( ! defined( 'ABSPATH' ) ) {
1012
exit;
1113
}

includes/acf-field-group-functions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ function acf_get_field_groups( $filter = array() ) {
126126
* @date 18/1/19
127127
* @since 5.7.10
128128
*
129-
* @param void
130129
* @return array
131130
*/
132131
function acf_get_raw_field_groups() {

includes/acf-form-functions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function acf_get_form_data( $name = '' ) {
4242
* @date 15/10/13
4343
* @since 5.0.0
4444
*
45-
* @param void
4645
* @return void
4746
*/
4847
function acf_form_data( $data = array() ) {

includes/acf-helper-functions.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ function acf_is_filter_enabled( $name = '' ) {
186186
* @date 14/7/16
187187
* @since 5.4.0
188188
*
189-
* @param void
190189
* @return array
191190
*/
192191
function acf_get_filters() {
@@ -216,7 +215,6 @@ function acf_set_filters( $filters = array() ) {
216215
* @date 14/7/16
217216
* @since 5.4.0
218217
*
219-
* @param void
220218
* @return array
221219
*/
222220
function acf_disable_filters() {
@@ -481,7 +479,6 @@ function acf_doing_action( $action ) {
481479
* @date 23/01/2015
482480
* @since 5.1.5
483481
*
484-
* @param void
485482
* @return string
486483
*/
487484
function acf_get_current_url() {

includes/acf-post-functions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* @date 29/8/17
77
* @since 5.6.2
88
*
9-
* @param void
109
* @return array
1110
*/
1211
function acf_get_post_templates() {

includes/acf-user-functions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ function acf_get_user_role_labels( $roles = array() ) {
9999
* @date 9/1/19
100100
* @since 5.7.10
101101
*
102-
* @param void
103102
* @return boolean
104103
*/
105104
function acf_allow_unfiltered_html() {

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

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
/**
43
* ACF Internal Post Type List class
54
*
@@ -16,6 +15,11 @@
1615

1716
if ( ! class_exists( 'ACF_Admin_Internal_Post_Type_List' ) ) :
1817

18+
/**
19+
* Internal Post Type List class.
20+
*
21+
* Adds logic to the edit page for internal post types.
22+
*/
1923
class ACF_Admin_Internal_Post_Type_List {
2024

2125

@@ -150,12 +154,12 @@ public function current_screen() {
150154
add_filter( "bulk_actions-edit-{$this->post_type}", array( $this, 'admin_table_bulk_actions' ), 10, 1 );
151155
add_action( 'admin_footer', array( $this, 'admin_footer' ), 1 );
152156

153-
if ( $this->view !== 'trash' ) {
157+
if ( 'trash' !== $this->view ) {
154158
add_filter( 'page_row_actions', array( $this, 'page_row_actions' ), 10, 2 );
155159
}
156160

157161
// Add hooks for "sync" view.
158-
if ( $this->view === 'sync' ) {
162+
if ( 'sync' === $this->view ) {
159163
add_action( 'admin_footer', array( $this, 'admin_footer__sync' ), 1 );
160164
}
161165

@@ -185,7 +189,7 @@ public function setup_sync() {
185189
continue;
186190

187191
// Ignore not local "json".
188-
} elseif ( $local !== 'json' ) {
192+
} elseif ( 'json' === $local ) {
189193
continue;
190194

191195
// Append to sync if not yet in database.
@@ -271,7 +275,7 @@ public function get_registration_error_state() {
271275
* @return array
272276
*/
273277
public function display_post_states( $post_states, $post ) {
274-
if ( $post->post_status === 'acf-disabled' ) {
278+
if ( 'acf-disabled' === $post->post_status ) {
275279
$post_states['acf-disabled'] = $this->get_disabled_post_state();
276280
}
277281

@@ -483,7 +487,7 @@ public function admin_table_bulk_actions( $actions ) {
483487
}
484488

485489
if ( $this->sync ) {
486-
if ( $this->view === 'sync' ) {
490+
if ( 'sync' === $this->view ) {
487491
$actions = array();
488492
}
489493
$actions['acfsync'] = __( 'Sync changes', 'secure-custom-fields' );
@@ -501,7 +505,7 @@ public function admin_table_bulk_actions( $actions ) {
501505
* @param integer $count The number of items the action was performed on.
502506
* @return string
503507
*/
504-
public function get_action_notice_text( $action, $count = 1 ) {
508+
public function get_action_notice_text( $action, $count = 1 ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Keep it for awareness when extending.
505509
return '';
506510
}
507511

@@ -773,19 +777,12 @@ public function check_sync() {
773777
$synced = array();
774778

775779
foreach ( $this->sync as $key => $post ) {
776-
if ( $post['key'] && in_array( $post['key'], $keys ) ) {
777-
// Import.
778-
} elseif ( $post['ID'] && in_array( $post['ID'], $keys ) ) {
779-
// Import.
780-
} else {
781-
// Ignore.
782-
continue;
780+
if ( ( $post['key'] && in_array( $post['key'], $keys, true ) ) || ( $post['ID'] && in_array( $post['ID'], $keys, true ) ) ) {
781+
$local_post = json_decode( file_get_contents( $files[ $key ] ), true );
782+
$local_post['ID'] = $post['ID'];
783+
$result = acf_import_internal_post_type( $local_post, $this->post_type );
784+
$synced[] = $result['ID'];
783785
}
784-
785-
$local_post = json_decode( file_get_contents( $files[ $key ] ), true );
786-
$local_post['ID'] = $post['ID'];
787-
$result = acf_import_internal_post_type( $local_post, $this->post_type );
788-
$synced[] = $result['ID'];
789786
}
790787

791788
// Redirect.
@@ -813,15 +810,15 @@ public function admin_table_views( $views ) {
813810
if ( $count ) {
814811
$views['sync'] = sprintf(
815812
'<a %s href="%s">%s <span class="count">(%s)</span></a>',
816-
( $this->view === 'sync' ? 'class="current"' : '' ),
813+
( 'sync' === $this->view ? 'class="current"' : '' ),
817814
esc_url( $this->get_admin_url( '&post_status=sync' ) ),
818815
esc_html( __( 'Sync available', 'secure-custom-fields' ) ),
819816
$count
820817
);
821818
}
822819

823820
// Modify table pagination args to match JSON data.
824-
if ( $this->view === 'sync' ) {
821+
if ( 'sync' === $this->view ) {
825822
$wp_list_table->set_pagination_args(
826823
array(
827824
'total_items' => $count,
@@ -903,11 +900,11 @@ public function admin_footer__sync() {
903900
echo '<tr>';
904901
foreach ( $columns as $column_name => $column_label ) {
905902
$el = 'td';
906-
if ( $column_name === 'cb' ) {
903+
if ( 'cb' === $column_name ) {
907904
$el = 'th';
908905
$classes = 'check-column';
909906
$column_label = '';
910-
} elseif ( $column_name === 'title' ) {
907+
} elseif ( 'title' === $column_name ) {
911908
$classes = "$column_name column-$column_name column-primary";
912909
} else {
913910
$classes = "$column_name column-$column_name";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function admin_footer() {
164164
* @since 5.3.8
165165
*
166166
* @param array $l10n The array of translated strings.
167-
* @return array $l10n
167+
* @return void
168168
*/
169169
public function admin_l10n( $l10n ) {
170170
// Override as necessary.

includes/admin/admin-notices.php

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed
22
/**
33
* ACF Admin Notices
44
*
@@ -25,37 +25,40 @@
2525
* @since 5.7.10
2626
*/
2727
if ( ! class_exists( 'ACF_Admin_Notice' ) ) :
28-
28+
/**
29+
* Class responsible for handling admin notices.
30+
*/
2931
class ACF_Admin_Notice extends ACF_Data {
3032

31-
/** @var array Storage for data. */
32-
var $data = array(
33+
/**
34+
* Storage for data.
35+
*
36+
* @var array
37+
*/
38+
public $data = array(
3339

34-
/** @type string Text displayed in notice. */
40+
/** Text displayed in notice. @type string */
3541
'text' => '',
3642

37-
/** @type string The type of notice (warning, error, success, info). */
43+
/** The type of notice (warning, error, success, info). @type string */
3844
'type' => 'info',
3945

40-
/** @type bool If the notice can be dismissed. */
46+
/** If the notice can be dismissed. @type bool */
4147
'dismissible' => true,
4248

43-
/** @type bool If the dismissed state should be persisted to ACF user preferences. */
49+
/** If the dismissed state should be persisted to ACF user preferences. @type bool */
4450
'persisted' => false,
4551
);
4652

4753
/**
48-
* render
49-
*
5054
* Renders the notice HTML.
5155
*
5256
* @date 27/12/18
5357
* @since 5.8.0
5458
*
55-
* @param void
5659
* @return void
5760
*/
58-
function render() {
61+
public function render() {
5962
$notice_text = $this->get( 'text' );
6063
$notice_type = $this->get( 'type' );
6164
$is_dismissible = $this->get( 'dismissible' );
@@ -75,8 +78,6 @@ function render() {
7578
endif; // class_exists check
7679

7780
/**
78-
* acf_new_admin_notice
79-
*
8081
* Instantiates and returns a new model.
8182
*
8283
* @date 23/12/18
@@ -98,14 +99,11 @@ function acf_new_admin_notice( $data = false ) {
9899
}
99100

100101
/**
101-
* acf_render_admin_notices
102-
*
103102
* Renders all admin notices HTML.
104103
*
105104
* @date 10/1/19
106105
* @since 5.7.10
107106
*
108-
* @param void
109107
* @return void
110108
*/
111109
function acf_render_admin_notices() {
@@ -125,17 +123,15 @@ function acf_render_admin_notices() {
125123
add_action( 'admin_notices', 'acf_render_admin_notices', 99 );
126124

127125
/**
128-
* acf_add_admin_notice
129-
*
130126
* Creates and returns a new notice.
131127
*
132128
* @date 17/10/13
133129
* @since 5.0.0
134130
*
135131
* @param string $text The admin notice text.
136-
* @param string $class The type of notice (warning, error, success, info).
137-
* @param boolean $dismissable Is this notification dismissible (default true) (since 5.11.0)
138-
* @param boolean $persisted Store once a notice has been dismissed per user and prevent showing it again. (since 6.1.0)
132+
* @param string $type The type of notice (warning, error, success, info).
133+
* @param boolean $dismissible Is this notification dismissible (default true) (since 5.11.0).
134+
* @param boolean $persisted Store once a notice has been dismissed per user and prevent showing it again. (since 6.1.0).
139135
* @return ACF_Admin_Notice
140136
*/
141137
function acf_add_admin_notice( $text = '', $type = 'info', $dismissible = true, $persisted = false ) {

0 commit comments

Comments
 (0)