fix phpcs tests
Some checks failed
PHP Code Checker / Run PHP Code Checker (pull_request) Failing after 40s
Unit Testing / Run phpunit tests (pull_request) Successful in 3m54s

This commit is contained in:
André Menrath 2024-09-21 10:28:39 +02:00
parent 837d8b13b2
commit 53a6e267aa
8 changed files with 158 additions and 43 deletions

View file

@ -1,4 +1,5 @@
name: Unit Testing
name: PHP Code Checker
on:
push:
branches:
@ -6,7 +7,7 @@ on:
pull_request:
jobs:
phpunit:
phpcs:
runs-on: ubuntu-latest
services:
mysql:
@ -16,7 +17,7 @@ jobs:
strategy:
matrix:
php-versions: ['8.1']
name: Run phpunit tests
name: Run PHP Code Checker
env:
extensions: mysql
key: cache-v1

View file

@ -1,47 +1,157 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
<description>Generally-applicable sniffs for WordPress plugins.</description>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Example Project" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<description>A custom set of rules to check for a WPized WordPress project</description>
<!--
#############################################################################
COMMAND LINE ARGUMENTS
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
#############################################################################
-->
<!-- What to scan -->
<file>.</file>
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/node_modules/</exclude-pattern>
<!-- How to scan -->
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
<arg value="sp"/> <!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
<!-- Exclude WP Core folders and files from being checked. -->
<exclude-pattern>/docroot/wp-admin/*</exclude-pattern>
<exclude-pattern>/docroot/wp-includes/*</exclude-pattern>
<exclude-pattern>/docroot/wp-*.php</exclude-pattern>
<exclude-pattern>/docroot/index.php</exclude-pattern>
<exclude-pattern>/docroot/xmlrpc.php</exclude-pattern>
<exclude-pattern>/docroot/wp-content/plugins/*</exclude-pattern>
<!-- Rules: Check PHP version compatibility -->
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.6-"/>
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
<rule ref="PHPCompatibilityWP"/>
<!-- Exclude the Composer Vendor directory. -->
<exclude-pattern>/vendor/*</exclude-pattern>
<!-- Rules: WordPress Coding Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
<config name="minimum_supported_wp_version" value="4.6"/>
<rule ref="WordPress"/>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
<property name="prefixes" type="array" value="my-plugin"/>
</properties>
<!-- Exclude the Node Modules directory. -->
<exclude-pattern>/node_modules/*</exclude-pattern>
<!-- Exclude minified Javascript files. -->
<exclude-pattern>*.min.js</exclude-pattern>
<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="."/>
<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>
<!--
#############################################################################
SET UP THE RULESETS
#############################################################################
-->
<!-- Include the WordPress-Extra standard. -->
<rule ref="WordPress-Extra">
<!--
We may want a middle ground though. The best way to do this is add the
entire ruleset, then rule by rule, remove ones that don't suit a project.
We can do this by running `phpcs` with the '-s' flag, which allows us to
see the names of the sniffs reporting errors.
Once we know the sniff names, we can opt to exclude sniffs which don't
suit our project like so.
The below two examples just show how you can exclude rules/error codes.
They are not intended as advice about which sniffs to exclude.
-->
<!--
<exclude name="WordPress.WhiteSpace.ControlStructureSpacing"/>
<exclude name="Modernize.FunctionCalls.Dirname.Nested"/>
-->
</rule>
<!-- Let's also check that everything is properly documented. -->
<rule ref="WordPress-Docs"/>
<!-- Add in some extra rules from other standards. -->
<rule ref="Generic.Commenting.Todo"/>
<!-- Check for PHP cross-version compatibility. -->
<!--
To enable this, the PHPCompatibilityWP standard needs
to be installed.
See the readme for installation instructions:
https://github.com/PHPCompatibility/PHPCompatibilityWP
For more information, also see:
https://github.com/PHPCompatibility/PHPCompatibility
-->
<!--
<config name="testVersion" value="5.6-"/>
<rule ref="PHPCompatibilityWP">
<include-pattern>*\.php</include-pattern>
</rule>
-->
<!--
#############################################################################
SNIFF SPECIFIC CONFIGURATION
#############################################################################
-->
<!--
To get the optimal benefits of using WordPressCS, we should add a couple of
custom properties.
Adjust the values of these properties to fit our needs.
For information on additional custom properties available, check out
the wiki:
https://github.com/WordPress/WordPress-Coding-Standards/wiki/Customizable-sniff-properties
-->
<config name="minimum_wp_version" value="6.6"/>
<rule ref="WordPress.WP.I18n">
<properties>
<!-- Value: replace the text domain used. -->
<property name="text_domain" type="array" value="my-plugin"/>
<property name="text_domain" type="array">
<element value="activitypub-event-extensions"/>
<element value="activitypub"/>
</property>
</properties>
</rule>
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="blank_line_check" value="true"/>
<property name="prefixes" type="array">
<element value="ACTIVITYPUB_EVENT_EXTENSIONS"/>
</property>
</properties>
</rule>
</ruleset>
<!--
#############################################################################
SELECTIVE EXCLUSIONS
Exclude specific files for specific sniffs and/or exclude sub-groups in sniffs.
#############################################################################
-->
<!--
Sometimes, you may want to exclude a certain directory, like your tests,
for select sniffs.
The below examples demonstrate how to do this.
In the example, the `GlobalVariablesOverride` rule is excluded for test files
as it is sometimes necessary to overwrite WP globals in test situations (just
don't forget to restore them after the test!).
Along the same lines, PHPUnit is getting stricter about using PSR-4 file names,
so excluding test files from the `WordPress.Files.Filename` sniff can be a
legitimate exclusion.
For more information on ruleset configuration options, check out the PHPCS wiki:
https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset
-->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<exclude-pattern>tests/*.php</exclude-pattern>
<exclude-pattern>templates/*.php</exclude-pattern>
</rule>
<rule ref="WordPress.WP.GlobalVariablesOverride">
<exclude-pattern>tests/*.php</exclude-pattern>
</rule>
<rule ref="WordPress.Files.FileName">
<exclude-pattern>tests/*.php</exclude-pattern>
</rule>
</ruleset>

View file

@ -44,7 +44,7 @@ Activitypub_Event_Extensions\Setup::get_instance();
*
* @todo This filter is temporary code needed to do local testing.
*/
add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 );
add_filter( 'http_request_host_is_external', 'activitypub_event_extensions_custom_http_request_host_is_external', 10, 3 );
/**
* Add a filter for http_request_host_is_external
@ -55,7 +55,7 @@ add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_extern
*
* @todo This filter is temporary code needed to do local testing.
*/
function custom_http_request_host_is_external( $is_external ) {
function activitypub_event_extensions_custom_http_request_host_is_external( $is_external ) {
$is_external = true;
return $is_external;
@ -68,11 +68,11 @@ function custom_http_request_host_is_external( $is_external ) {
*
* @todo This filter is temporary code needed to do local testing.
*/
add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 );
add_filter( 'https_ssl_verify', 'activitypub_event_extensions_dont_verify_local_dev_https', 10, 3 );
/**
* TODO: remove it.
*/
function dont_verify_local_dev_https() {
function activitypub_event_extensions_dont_verify_local_dev_https() {
return false;
}

View file

@ -6,6 +6,8 @@
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
use EM_Event;
use Activitypub\Activity\Extended_Object\Event;

View file

@ -6,6 +6,8 @@
* @license AGPL-3.0-or-later
*/
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
use Activitypub\Model\Blog;
use Activitypub\Activity\Extended_Object\Event as Event_Object;

View file

@ -37,7 +37,7 @@ class Settings_Page {
public static function admin_menu(): void {
\add_options_page(
'Activitypub Event Extension',
__( 'ActivityPub Events', 'activitypub_event_extensions' ),
__( 'ActivityPub Events', 'activitypub-event-extensions' ),
'manage_options',
self::SETTINGS_SLUG,
array( self::STATIC, 'settings_page' )

View file

@ -76,7 +76,7 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
<div class="box">
<h2> <?php esc_html_e( 'Default ActivityPub Event Category', 'activitypub-event-extensions' ); ?> </h2>
<p> <?php esc_html_e( 'To help visitors find events more easily, the community created a set of basic event categories. Please select the category that best matches the majority of the events you organize.' ); ?> </p>
<p> <?php esc_html_e( 'To help visitors find events more easily, the community created a set of basic event categories. Please select the category that best matches the majority of the events you organize.', 'activitypub-event-extensions' ); ?> </p>
<table class="form-table">
<tr>
<th scope="row"> <?php esc_html_e( 'Default Category', 'activitypub-event-extensions' ); ?> </th>
@ -96,7 +96,7 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
<?php if ( ! empty( $event_terms ) ) : ?>
<div class="box">
<h2> <?php esc_html_e( 'Advanced Event Category Settings', 'activitypub-event-extensions' ); ?> </h2>
<p> <?php esc_html_e( 'Take more control by adjusting how your event categories are mapped to the basic category set used in ActivityPub. This option lets you override the default selection above, ensuring more accurate categorization and better visibility for your events.' ); ?> </p>
<p> <?php esc_html_e( 'Take more control by adjusting how your event categories are mapped to the basic category set used in ActivityPub. This option lets you override the default selection above, ensuring more accurate categorization and better visibility for your events.', 'activitypub-event-extensions' ); ?> </p>
<table class="form-table">
<?php foreach ( $event_terms as $event_term ) { ?>
<tr>