Skip to content

Various PHPCS updates #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<!-- Exclude package files -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/lang/*</exclude-pattern>

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

<rule ref="WordPress" phpcbf-only="true" />
<rule ref="WordPress">
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores" /> <!-- 'acf/hookname' is used throughout. -->
<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar" /> <!-- This is trivial and not really useful today. -->
<exclude name="WordPress.Files.FileName.InvalidClassFileName" /> <!-- Refactoring of this scale is not in scope yet.-->
</rule>
<rule ref="WordPress.Security.EscapeOutput">
<properties>
<property name="customEscapingFunctions" type="array">
<element value="acf_esc_attrs" /> <!-- This function takes an associated array and escapes both the attr title and attr value. -->
<element value="acf_esc_html" />
</property>
</properties>
</rule>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
Expand Down
4 changes: 3 additions & 1 deletion acf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* This file is for the converting of sites from acf.php to secure-custom-fields.php as the main plugin file.
*
* Under this slug, acf.php would have been the main plugin file in < 6.4.0-beta4.
*
* @package wordpress/secure-custom-fields
*/

// Exit if accessed directly
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand Down
1 change: 0 additions & 1 deletion includes/acf-field-group-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ function acf_get_field_groups( $filter = array() ) {
* @date 18/1/19
* @since 5.7.10
*
* @param void
* @return array
*/
function acf_get_raw_field_groups() {
Expand Down
1 change: 0 additions & 1 deletion includes/acf-form-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ function acf_get_form_data( $name = '' ) {
* @date 15/10/13
* @since 5.0.0
*
* @param void
* @return void
*/
function acf_form_data( $data = array() ) {
Expand Down
3 changes: 0 additions & 3 deletions includes/acf-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ function acf_is_filter_enabled( $name = '' ) {
* @date 14/7/16
* @since 5.4.0
*
* @param void
* @return array
*/
function acf_get_filters() {
Expand Down Expand Up @@ -216,7 +215,6 @@ function acf_set_filters( $filters = array() ) {
* @date 14/7/16
* @since 5.4.0
*
* @param void
* @return array
*/
function acf_disable_filters() {
Expand Down Expand Up @@ -481,7 +479,6 @@ function acf_doing_action( $action ) {
* @date 23/01/2015
* @since 5.1.5
*
* @param void
* @return string
*/
function acf_get_current_url() {
Expand Down
1 change: 0 additions & 1 deletion includes/acf-post-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @date 29/8/17
* @since 5.6.2
*
* @param void
* @return array
*/
function acf_get_post_templates() {
Expand Down
1 change: 0 additions & 1 deletion includes/acf-user-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ function acf_get_user_role_labels( $roles = array() ) {
* @date 9/1/19
* @since 5.7.10
*
* @param void
* @return boolean
*/
function acf_allow_unfiltered_html() {
Expand Down
43 changes: 20 additions & 23 deletions includes/admin/admin-internal-post-type-list.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* ACF Internal Post Type List class
*
Expand All @@ -16,6 +15,11 @@

if ( ! class_exists( 'ACF_Admin_Internal_Post_Type_List' ) ) :

/**
* Internal Post Type List class.
*
* Adds logic to the edit page for internal post types.
*/
class ACF_Admin_Internal_Post_Type_List {


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

if ( $this->view !== 'trash' ) {
if ( 'trash' !== $this->view ) {
add_filter( 'page_row_actions', array( $this, 'page_row_actions' ), 10, 2 );
}

// Add hooks for "sync" view.
if ( $this->view === 'sync' ) {
if ( 'sync' === $this->view ) {
add_action( 'admin_footer', array( $this, 'admin_footer__sync' ), 1 );
}

Expand Down Expand Up @@ -185,7 +189,7 @@ public function setup_sync() {
continue;

// Ignore not local "json".
} elseif ( $local !== 'json' ) {
} elseif ( 'json' === $local ) {
continue;

// Append to sync if not yet in database.
Expand Down Expand Up @@ -271,7 +275,7 @@ public function get_registration_error_state() {
* @return array
*/
public function display_post_states( $post_states, $post ) {
if ( $post->post_status === 'acf-disabled' ) {
if ( 'acf-disabled' === $post->post_status ) {
$post_states['acf-disabled'] = $this->get_disabled_post_state();
}

Expand Down Expand Up @@ -483,7 +487,7 @@ public function admin_table_bulk_actions( $actions ) {
}

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

Expand Down Expand Up @@ -773,19 +777,12 @@ public function check_sync() {
$synced = array();

foreach ( $this->sync as $key => $post ) {
if ( $post['key'] && in_array( $post['key'], $keys ) ) {
// Import.
} elseif ( $post['ID'] && in_array( $post['ID'], $keys ) ) {
// Import.
} else {
// Ignore.
continue;
if ( ( $post['key'] && in_array( $post['key'], $keys, true ) ) || ( $post['ID'] && in_array( $post['ID'], $keys, true ) ) ) {
$local_post = json_decode( file_get_contents( $files[ $key ] ), true );
$local_post['ID'] = $post['ID'];
$result = acf_import_internal_post_type( $local_post, $this->post_type );
$synced[] = $result['ID'];
}

$local_post = json_decode( file_get_contents( $files[ $key ] ), true );
$local_post['ID'] = $post['ID'];
$result = acf_import_internal_post_type( $local_post, $this->post_type );
$synced[] = $result['ID'];
}

// Redirect.
Expand Down Expand Up @@ -813,15 +810,15 @@ public function admin_table_views( $views ) {
if ( $count ) {
$views['sync'] = sprintf(
'<a %s href="%s">%s <span class="count">(%s)</span></a>',
( $this->view === 'sync' ? 'class="current"' : '' ),
( 'sync' === $this->view ? 'class="current"' : '' ),
esc_url( $this->get_admin_url( '&post_status=sync' ) ),
esc_html( __( 'Sync available', 'secure-custom-fields' ) ),
$count
);
}

// Modify table pagination args to match JSON data.
if ( $this->view === 'sync' ) {
if ( 'sync' === $this->view ) {
$wp_list_table->set_pagination_args(
array(
'total_items' => $count,
Expand Down Expand Up @@ -903,11 +900,11 @@ public function admin_footer__sync() {
echo '<tr>';
foreach ( $columns as $column_name => $column_label ) {
$el = 'td';
if ( $column_name === 'cb' ) {
if ( 'cb' === $column_name ) {
$el = 'th';
$classes = 'check-column';
$column_label = '';
} elseif ( $column_name === 'title' ) {
} elseif ( 'title' === $column_name ) {
$classes = "$column_name column-$column_name column-primary";
} else {
$classes = "$column_name column-$column_name";
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/admin-internal-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function admin_footer() {
* @since 5.3.8
*
* @param array $l10n The array of translated strings.
* @return array $l10n
* @return void
*/
public function admin_l10n( $l10n ) {
// Override as necessary.
Expand Down
40 changes: 18 additions & 22 deletions includes/admin/admin-notices.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed
/**
* ACF Admin Notices
*
Expand All @@ -25,37 +25,40 @@
* @since 5.7.10
*/
if ( ! class_exists( 'ACF_Admin_Notice' ) ) :

/**
* Class responsible for handling admin notices.
*/
class ACF_Admin_Notice extends ACF_Data {

/** @var array Storage for data. */
var $data = array(
/**
* Storage for data.
*
* @var array
*/
public $data = array(

/** @type string Text displayed in notice. */
/** Text displayed in notice. @type string */
'text' => '',

/** @type string The type of notice (warning, error, success, info). */
/** The type of notice (warning, error, success, info). @type string */
'type' => 'info',

/** @type bool If the notice can be dismissed. */
/** If the notice can be dismissed. @type bool */
'dismissible' => true,

/** @type bool If the dismissed state should be persisted to ACF user preferences. */
/** If the dismissed state should be persisted to ACF user preferences. @type bool */
'persisted' => false,
);

/**
* render
*
* Renders the notice HTML.
*
* @date 27/12/18
* @since 5.8.0
*
* @param void
* @return void
*/
function render() {
public function render() {
$notice_text = $this->get( 'text' );
$notice_type = $this->get( 'type' );
$is_dismissible = $this->get( 'dismissible' );
Expand All @@ -75,8 +78,6 @@ function render() {
endif; // class_exists check

/**
* acf_new_admin_notice
*
* Instantiates and returns a new model.
*
* @date 23/12/18
Expand All @@ -98,14 +99,11 @@ function acf_new_admin_notice( $data = false ) {
}

/**
* acf_render_admin_notices
*
* Renders all admin notices HTML.
*
* @date 10/1/19
* @since 5.7.10
*
* @param void
* @return void
*/
function acf_render_admin_notices() {
Expand All @@ -125,17 +123,15 @@ function acf_render_admin_notices() {
add_action( 'admin_notices', 'acf_render_admin_notices', 99 );

/**
* acf_add_admin_notice
*
* Creates and returns a new notice.
*
* @date 17/10/13
* @since 5.0.0
*
* @param string $text The admin notice text.
* @param string $class The type of notice (warning, error, success, info).
* @param boolean $dismissable Is this notification dismissible (default true) (since 5.11.0)
* @param boolean $persisted Store once a notice has been dismissed per user and prevent showing it again. (since 6.1.0)
* @param string $type The type of notice (warning, error, success, info).
* @param boolean $dismissible Is this notification dismissible (default true) (since 5.11.0).
* @param boolean $persisted Store once a notice has been dismissed per user and prevent showing it again. (since 6.1.0).
* @return ACF_Admin_Notice
*/
function acf_add_admin_notice( $text = '', $type = 'info', $dismissible = true, $persisted = false ) {
Expand Down
Loading