Skip to content

Commit

Permalink
Merge pull request #61 from Yoast/JRF/upgrade-to-yoastcs-2.0
Browse files Browse the repository at this point in the history
PHPCS: Update to YoastCS 2.0.0
  • Loading branch information
karlijnbok authored Jan 9, 2020
2 parents 641fc28 + bedb221 commit d98500c
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 102 deletions.
44 changes: 28 additions & 16 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@
#############################################################################
-->

<rule ref="Yoast"/>
<rule ref="Yoast">
<properties>
<!-- Provide the plugin specific prefix for use with namespace and hook names. -->
<property name="prefixes" type="array">
<element value="Yoast\WP\Comment"/>
<element value="yoast_comment"/>
</property>
</properties>
</rule>


<!--
Expand All @@ -54,34 +62,29 @@
<rule ref="Yoast.Files.FileName">
<properties>
<!-- Don't trigger on the main file as renaming it would deactivate the plugin. -->
<property name="exclude" type="array">
<property name="excluded_files_strict_check" type="array">
<element value="yoast-comment-hacks.php"/>
</property>

<!-- Remove the following prefixes from the names of object structures. -->
<property name="prefixes" type="array">
<property name="oo_prefixes" type="array">
<element value="yoast_comment"/>
</property>
</properties>

<exclude-pattern>*/deprecated/deprecated-classes\.php$</exclude-pattern>
</rule>

<!-- Verify that everything in the global namespace is prefixed with a plugin specific prefix. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Provide the prefixes to look for. -->
<property name="prefixes" type="array">
<!-- Temporarily allowed until the prefixes are fixed. -->
<element value="yoast_ch"/>
<element value="yst_comment"/>

<!-- These are the new prefixes which all code should comply with in the future. -->
<element value="yoast_comment"/>
<element value="Yoast\WP\Comment"/>
</property>
</properties>
<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
#############################################################################
-->

<!-- Valid: These classes were deprecated to comply with the prefixing rules. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>*/deprecated/*\.php$</exclude-pattern>
</rule>

Expand All @@ -93,6 +96,15 @@
#############################################################################
-->

<!-- Until all prefixes are fixed, some exceptions are allowed to the PrefixAllGlobals sniff. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array" extend="true">
<element value="yst_comment"/>
</property>
</properties>
</rule>

<!-- Direct database queries need careful review.
Ticket: https://github.com/Yoast/comment-hacks/issues/50
-->
Expand Down
68 changes: 42 additions & 26 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Admin {
*
* @var array
*/
private $options = array();
private $options = [];

/**
* The absolute minimum comment length when this plugin is enabled.
Expand All @@ -48,18 +48,18 @@ public function __construct() {
$this->options = Hacks::get_options();

// Hook into init for registration of the option and the language files.
\add_action( 'admin_init', array( $this, 'init' ) );
\add_action( 'admin_init', [ $this, 'init' ] );

// Register the settings page.
\add_action( 'admin_menu', array( $this, 'add_config_page' ) );
\add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
\add_action( 'admin_menu', [ $this, 'add_config_page' ] );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );

// Register a link to the settings page on the plugins overview page.
\add_filter( 'plugin_action_links', array( $this, 'filter_plugin_actions' ), 10, 2 );
\add_filter( 'plugin_action_links', [ $this, 'filter_plugin_actions' ], 10, 2 );

// Filter the comment notification recipients.
\add_action( 'post_comment_status_meta_box-options', array( $this, 'reroute_comment_emails_option' ) );
\add_action( 'save_post', array( $this, 'save_reroute_comment_emails' ) );
\add_action( 'post_comment_status_meta_box-options', [ $this, 'reroute_comment_emails_option' ] );
\add_action( 'save_post', [ $this, 'save_reroute_comment_emails' ] );

new Comment_Parent();
}
Expand All @@ -72,10 +72,10 @@ public function init() {
\register_setting(
Hacks::$option_name,
Hacks::$option_name,
array(
[
$this,
'options_validate',
)
]
);
}

Expand All @@ -94,14 +94,14 @@ public function enqueue() {
\wp_enqueue_style(
'yoast-comment-hacks-admin-css',
\plugins_url( 'admin/assets/css/yoast-comment-hacks.css', \YOAST_COMMENT_HACKS_FILE ),
array(),
[],
\YOAST_COMMENT_HACKS_VERSION
);

\wp_enqueue_script(
'yoast-comment-hacks-admin-js',
\plugins_url( 'admin/assets/js/yoast-comment-hacks.min.js', \YOAST_COMMENT_HACKS_FILE ),
array(),
[],
\YOAST_COMMENT_HACKS_VERSION,
true
);
Expand All @@ -115,11 +115,11 @@ public function enqueue() {
*/
public function register_i18n_promo_class() {
new Yoast_I18n_WordPressOrg_v3(
array(
[
'textdomain' => 'yoast-comment-hacks',
'plugin_name' => 'Yoast Comment Hacks',
'hook' => 'yoast_ch_admin_footer',
)
'hook' => 'Yoast\WP\Comment\admin_footer',
]
);
}

Expand All @@ -136,27 +136,43 @@ public function reroute_comment_emails_option() {
* This filter allows filtering which roles should be shown in the dropdown for notifications.
* Defaults to contributor and up.
*
* @deprecated 1.6.0. Use the {@see 'Yoast\WP\Comment\notification_roles'} filter instead.
*
* @param array $roles Array with user roles.
*/
$roles = \apply_filters(
$roles = \apply_filters_deprecated(
'yoast_comment_hacks_notification_roles',
array(
'author',
'contributor',
'editor',
'administrator',
)
[
[
'author',
'contributor',
'editor',
'administrator',
],
],
'Yoast Comment 1.6.0',
'Yoast\WP\Comment\notification_roles'
);

/**
* This filter allows filtering which roles should be shown in the dropdown for notifications.
* Defaults to contributor and up.
*
* @since 1.6.0
*
* @param array $roles Array with user roles.
*/
$roles = \apply_filters( 'Yoast\WP\Comment\notification_roles', $roles );

\wp_dropdown_users(
array(
[
'selected' => \get_post_meta( $post_id, self::NOTIFICATION_RECIPIENT_KEY, true ),
'show_option_none' => 'Post author',
'name' => 'comment_notification_recipient',
'id' => 'comment_notification_recipient',
'role__in' => $roles,
'option_none_value' => 0,
)
]
);
}

Expand Down Expand Up @@ -191,7 +207,7 @@ public function options_validate( $input ) {
$input['clean_emails'] = isset( $input['clean_emails'] ) ? 1 : 0;
$input['version'] = \YOAST_COMMENT_HACKS_VERSION;

foreach ( array( 'email_subject', 'email_body', 'mass_email_body' ) as $key ) {
foreach ( [ 'email_subject', 'email_body', 'mass_email_body' ] as $key ) {
if ( $input[ $key ] === '' ) {
$input[ $key ] = $defaults[ $key ];
}
Expand All @@ -215,10 +231,10 @@ public function add_config_page() {
\__( 'Comment Hacks', 'yoast-comment-hacks' ),
'manage_options',
$this->hook,
array(
[
$this,
'config_page',
)
]
);
}

Expand Down
8 changes: 4 additions & 4 deletions admin/comment-parent.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Comment_Parent {
*/
public function __construct() {
// The hooks for editing and saving the comment parent.
\add_action( 'admin_menu', array( $this, 'load_comment_parent_box' ) );
\add_action( 'edit_comment', array( $this, 'update_comment_parent' ) );
\add_action( 'admin_menu', [ $this, 'load_comment_parent_box' ] );
\add_action( 'edit_comment', [ $this, 'update_comment_parent' ] );
}

/**
Expand All @@ -36,10 +36,10 @@ public function load_comment_parent_box() {
\add_meta_box(
'comment_parent',
'Comment Parent',
array(
[
$this,
'comment_parent_box',
),
],
'comment',
'normal'
);
Expand Down
16 changes: 13 additions & 3 deletions admin/views/config-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@
<?php
// A dropdown of all pages in the current WP install.
wp_dropdown_pages(
array(
[
'depth' => 0,
'id' => 'redirect_page',
// phpcs:ignore WordPress.Security.EscapeOutput -- This is a hard-coded string, just passed around as a variable.
'name' => $yoast_comment_option_name . '[redirect_page]',
'option_none_value' => 0,
'selected' => ( isset( $this->options['redirect_page'] ) ? (int) $this->options['redirect_page'] : 0 ),
'show_option_none' => esc_html__( 'Don\'t redirect first time commenters', 'yoast-comment-hacks' ),
)
]
);

if ( isset( $this->options['redirect_page'] ) && $this->options['redirect_page'] !== 0 ) {
Expand Down Expand Up @@ -187,5 +187,15 @@
/**
* Action hook to allow other plugins to add additional information to the
* Yoast Comment Hacks admin page.
*
* @deprecated 1.6.0. Use the {@see 'Yoast\WP\Comment\admin_footer'} action instead.
*/
do_action_deprecated( 'yoast_ch_admin_footer', [], 'Yoast Comment 1.6.0', 'Yoast\WP\Comment\admin_footer' );

/**
* Action hook to allow other plugins to add additional information to the
* Yoast Comment Hacks admin page.
*
* @since 1.6.0
*/
do_action( 'yoast_ch_admin_footer' );
do_action( 'Yoast\WP\Comment\admin_footer' );
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"yoast/i18n-module": "^3.1.1"
},
"require-dev": {
"yoast/yoastcs": "^1.3.0"
"yoast/yoastcs": "^2.0.0"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -45,7 +45,7 @@
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --config-set default_standard Yoast"
],
"check-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.6-"
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
],
"fix-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
Expand Down
20 changes: 11 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d98500c

Please sign in to comment.