Skip to content
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

WPCS 3.1, PHPStan and workflows #123

Merged
merged 6 commits into from
Sep 18, 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
31 changes: 31 additions & 0 deletions .github/workflows/composer-diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Composer Diff
on:
pull_request:
paths:
- 'composer.lock'
jobs:
composer-diff:
name: Composer Diff
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout
with:
fetch-depth: 0 # Required to make it possible to compare with PR base branch

- name: Generate composer diff
id: composer_diff # To reference the output in comment
uses: IonBazan/composer-diff-action@v1

- uses: marocchino/sticky-pull-request-comment@v2
# An empty diff result will break this action.
if: ${{ steps.composer_diff.outputs.composer_diff_exit_code != 0 }}
with:
header: composer-diff # Creates a collapsed comment with the report
message: |
<details>
<summary>Composer package changes</summary>

${{ steps.composer_diff.outputs.composer_diff }}

</details>
36 changes: 36 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run PHPStan

on:
# Run on pushes to select branches and on all pull requests.
push:
branches:
- main
- develop
- 'release/[0-9]+.[0-9]+*'
- 'hotfix/[0-9]+.[0-9]+*'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
phpstan:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 'latest'
coverage: none
tools: composer, cs2pr

- name: Install PHP dependencies
uses: ramsey/composer-install@v2
with:
composer-options: '--prefer-dist --no-scripts'

- name: PHPStan
run: composer phpstan
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@ jobs:
matrix:
include:
- php_version: '7.4'
wp_version: '5.9'
wp_version: '6.2'
multisite: false

# WP 5.6 is the earliest version which (sort of) supports PHP 8.0.
- php_version: '8.0'
wp_version: '5.9'
wp_version: '6.2'
multisite: false

# WP 5.9 is the earliest version which (sort of) supports PHP 8.1.
- php_version: '8.1'
wp_version: 'latest'
multisite: true

# WP 6.1 is the earliest version which supports PHP 8.2.
- php_version: '8.2'
wp_version: '6.1'
wp_version: '6.4'
multisite: true

name: "Integration Test: PHP ${{ matrix.php_version }} | WP ${{ matrix.wp_version }}${{ matrix.multisite == true && ' (+ ms)' || '' }}"
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/wp-version-checker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "WordPress version checker"
on:
push:
branches:
- develop
- main
schedule:
- cron: '0 0 * * *'

permissions:
issues: write

jobs:
wordpress-version-checker:
runs-on: ubuntu-latest
steps:
- name: WordPress version checker
uses: skaut/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ class Admin {

/**
* Holds the plugins options.
*
* @var mixed[]
*/
private array $options = [];
public array $options = [];

/**
* The absolute minimum comment length when this plugin is enabled.
Expand Down Expand Up @@ -71,7 +73,7 @@ public function show_forward_status( $comment_text, $comment ): string {
return $comment_text;
}

$ch_forwarded = \get_comment_meta( $comment->comment_ID, 'ch_forwarded' );
$ch_forwarded = \get_comment_meta( (int) $comment->comment_ID, 'ch_forwarded' );
if ( $ch_forwarded ) {
/* translators: %s is replaced by the name you're forwarding to. */
$pre = '<div style="background: #fff;border: 1px solid #46b450;border-left-width: 4px;box-shadow: 0 1px 1px rgba(0,0,0,.04);margin: 5px 15px 2px 0;padding: 1px 12px 1px;"><p><strong>' . \sprintf( \esc_html__( 'This comment was forwarded to %s.', 'comment-hacks' ), \esc_html( $this->options['forward_name'] ) ) . '</strong></p></div>';
Expand Down Expand Up @@ -112,7 +114,7 @@ public function forward_comment(): void {
/* translators: %1$s is replaced by (a link to) the blog's name, %2$s by (a link to) the title of the post. */
\esc_html__( 'This comment was forwarded from %1$s where it was left on: %2$s.', 'comment-hacks' ),
'<a href=" ' . \esc_url( \get_site_url() ) . ' ">' . \esc_html( \get_bloginfo( 'name' ) ) . '</a>',
'<a href="' . \esc_url( \get_permalink( $comment->comment_post_ID ) ) . '">' . esc_html( \get_the_title( $comment->comment_post_ID ) ) . '</a>'
'<a href="' . \esc_url( \get_permalink( (int) $comment->comment_post_ID ) ) . '">' . esc_html( \get_the_title( (int) $comment->comment_post_ID ) ) . '</a>'
) . "\n\n";

if ( ! empty( $this->options['forward_extra'] ) ) {
Expand Down Expand Up @@ -360,6 +362,8 @@ private function sanitize_string( $value, $default ) {

/**
* Register the config page for all users that have the manage_options capability.
*
* @return void
*/
public function add_config_page() {
\add_options_page(
Expand Down
6 changes: 6 additions & 0 deletions admin/comment-parent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public function __construct() {
* Shows the comment parent box where you can change the comment parent.
*
* @param object $comment The comment object.
*
* @return void
*/
public function comment_parent_box( $comment ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Param used in included file.
require_once \EMILIA_COMMENT_HACKS_PATH . 'admin/views/comment-parent-box.php';
}

/**
* Adds the comment parent box to the meta box.
*
* @return void
*/
public function load_comment_parent_box() {
if ( \function_exists( 'add_meta_box' ) ) {
Expand All @@ -45,6 +49,8 @@ public function load_comment_parent_box() {

/**
* Updates the comment parent field.
*
* @return void
*/
public function update_comment_parent() {
$comment_parent = \filter_input( \INPUT_POST, 'epch_comment_parent', \FILTER_VALIDATE_INT );
Expand Down
5 changes: 5 additions & 0 deletions admin/views/comment-parent-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* Parent Box view.
*/

/**
* The comment object.
*
* @var WP_Comment $comment
*/
?>
<div class="inside">
<table class="form-table editcomment">
Expand Down
10 changes: 6 additions & 4 deletions admin/views/config-page.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* Config page admin view.
*
* @var \EmiliaProjects\WP\Comment\Admin\Admin $this
*/

use EmiliaProjects\WP\Comment\Inc\Hacks;
Expand Down Expand Up @@ -150,12 +152,12 @@ class="small-text"
wp_dropdown_pages(
[
'depth' => 0,
'id' => 'comment_policy_page',
'name' => esc_attr( Hacks::$option_name . '[comment_policy_page]' ),
'option_none_value' => 0,
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $selected is not put out, only compared against.
'selected' => ( isset( $this->options['comment_policy_page'] ) ? (int) $this->options['comment_policy_page'] : 0 ),
'name' => esc_attr( Hacks::$option_name . '[comment_policy_page]' ),
'id' => 'comment_policy_page',
'show_option_none' => esc_html__( 'Select comment policy page', 'comment-hacks' ),
'option_none_value' => '',
]
);
?>
Expand Down Expand Up @@ -277,7 +279,7 @@ class="regular-text"
'id' => 'redirect_page',
// phpcs:ignore WordPress.Security.EscapeOutput -- This is a hard-coded string, just passed around as a variable.
'name' => Hacks::$option_name . '[redirect_page]',
'option_none_value' => 0,
'option_none_value' => '',
'selected' => ( isset( $this->options['redirect_page'] ) ? (int) $this->options['redirect_page'] : 0 ),
'show_option_none' => esc_html__( 'Don\'t redirect first time commenters', 'comment-hacks' ),
]
Expand Down
29 changes: 18 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
{
"name": "jdevalk/comment-hacks",
"name": "emilia-capital/comment-hacks",
"description": "Make comments management easier by applying some of the simple hacks Joost gathered over decades of using WordPress.",
"keywords": [
"comments",
"spam",
"emails"
],
"homepage": "https://emilia.capital/",
"homepage": "https://wordpress.org/plugins/yoast-comment-hacks/",
"license": "GPL-3.0-or-later",
"authors": [
{
"name": "Joost de Valk",
"email": "[email protected]",
"homepage": "https://joost.blog"
"name": "Team Emilia Projects",
"email": "[email protected]",
"homepage": "https://emilia.capital"
}
],
"type": "wordpress-plugin",
"support": {
"issues": "https://github.com/jdevalk/comment-hacks/issues",
"forum": "https://wordpress.org/support/plugin/comment-hacks",
"wiki": "https://github.com/jdevalk/comment-hacks/wiki",
"source": "https://github.com/jdevalk/comment-hacks"
"issues": "https://github.com/emilia-capital/comment-hacks/issues",
"forum": "https://wordpress.org/support/plugin/yoast-comment-hacks",
"wiki": "https://github.com/emilia-capital/comment-hacks/wiki",
"source": "https://github.com/emilia-capital/comment-hacks"
},
"require": {
"php": ">=7.4",
"composer/installers": "^1.12.0"
},
"require-dev": {
"yoast/yoastcs": "^2.2.1",
"yoast/wp-test-utils": "^1.1.1"
"yoast/wp-test-utils": "^1.1.1",
"phpstan/phpstan": "^1.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.3"
},
"config": {
"platform": {
"php": "7.4"
},
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
},
"minimum-stability": "dev",
Expand All @@ -62,6 +66,9 @@
],
"test": [
"@php ./vendor/phpunit/phpunit/phpunit"
],
"phpstan": [
"@php ./vendor/bin/phpstan analyse --memory-limit=2048M ."
]
}
}
Loading
Loading