fix phpcs tests
This commit is contained in:
parent
837d8b13b2
commit
53a6e267aa
8 changed files with 158 additions and 43 deletions
|
@ -1,4 +1,5 @@
|
||||||
name: Unit Testing
|
name: PHP Code Checker
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
|
@ -6,7 +7,7 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
phpunit:
|
phpcs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
services:
|
services:
|
||||||
mysql:
|
mysql:
|
||||||
|
@ -16,7 +17,7 @@ jobs:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
php-versions: ['8.1']
|
php-versions: ['8.1']
|
||||||
name: Run phpunit tests
|
name: Run PHP Code Checker
|
||||||
env:
|
env:
|
||||||
extensions: mysql
|
extensions: mysql
|
||||||
key: cache-v1
|
key: cache-v1
|
||||||
|
|
176
.phpcs.xml.dist
176
.phpcs.xml.dist
|
@ -1,47 +1,157 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<ruleset name="WordPress Coding Standards based custom ruleset for your plugin">
|
<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>Generally-applicable sniffs for WordPress plugins.</description>
|
|
||||||
|
<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>
|
<file>.</file>
|
||||||
<exclude-pattern>/vendor/</exclude-pattern>
|
|
||||||
<exclude-pattern>/node_modules/</exclude-pattern>
|
|
||||||
|
|
||||||
<!-- How to scan -->
|
<!-- Exclude WP Core folders and files from being checked. -->
|
||||||
<!-- Usage instructions: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage -->
|
<exclude-pattern>/docroot/wp-admin/*</exclude-pattern>
|
||||||
<!-- Annotated ruleset: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml -->
|
<exclude-pattern>/docroot/wp-includes/*</exclude-pattern>
|
||||||
<arg value="sp"/> <!-- Show sniff and progress -->
|
<exclude-pattern>/docroot/wp-*.php</exclude-pattern>
|
||||||
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
|
<exclude-pattern>/docroot/index.php</exclude-pattern>
|
||||||
<arg name="colors"/>
|
<exclude-pattern>/docroot/xmlrpc.php</exclude-pattern>
|
||||||
<arg name="extensions" value="php"/>
|
<exclude-pattern>/docroot/wp-content/plugins/*</exclude-pattern>
|
||||||
<arg name="parallel" value="8"/><!-- Enables parallel processing when available for faster results. -->
|
|
||||||
|
|
||||||
<!-- Rules: Check PHP version compatibility -->
|
<!-- Exclude the Composer Vendor directory. -->
|
||||||
<!-- https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
|
<exclude-pattern>/vendor/*</exclude-pattern>
|
||||||
<config name="testVersion" value="5.6-"/>
|
|
||||||
<!-- https://github.com/PHPCompatibility/PHPCompatibilityWP -->
|
|
||||||
<rule ref="PHPCompatibilityWP"/>
|
|
||||||
|
|
||||||
<!-- Rules: WordPress Coding Standards -->
|
<!-- Exclude the Node Modules directory. -->
|
||||||
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards -->
|
<exclude-pattern>/node_modules/*</exclude-pattern>
|
||||||
<!-- https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties -->
|
|
||||||
<config name="minimum_supported_wp_version" value="4.6"/>
|
<!-- Exclude minified Javascript files. -->
|
||||||
<rule ref="WordPress"/>
|
<exclude-pattern>*.min.js</exclude-pattern>
|
||||||
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
|
|
||||||
<properties>
|
<!-- Strip the filepaths down to the relevant bit. -->
|
||||||
<!-- Value: replace the function, class, and variable prefixes used. Separate multiple prefixes with a comma. -->
|
<arg name="basepath" value="."/>
|
||||||
<property name="prefixes" type="array" value="my-plugin"/>
|
|
||||||
</properties>
|
<!-- 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>
|
</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">
|
<rule ref="WordPress.WP.I18n">
|
||||||
<properties>
|
<properties>
|
||||||
<!-- Value: replace the text domain used. -->
|
<property name="text_domain" type="array">
|
||||||
<property name="text_domain" type="array" value="my-plugin"/>
|
<element value="activitypub-event-extensions"/>
|
||||||
|
<element value="activitypub"/>
|
||||||
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
</rule>
|
</rule>
|
||||||
<rule ref="WordPress.WhiteSpace.ControlStructureSpacing">
|
|
||||||
|
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
|
||||||
<properties>
|
<properties>
|
||||||
<property name="blank_line_check" value="true"/>
|
<property name="prefixes" type="array">
|
||||||
|
<element value="ACTIVITYPUB_EVENT_EXTENSIONS"/>
|
||||||
|
</property>
|
||||||
</properties>
|
</properties>
|
||||||
</rule>
|
</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>
|
|
@ -44,7 +44,7 @@ Activitypub_Event_Extensions\Setup::get_instance();
|
||||||
*
|
*
|
||||||
* @todo This filter is temporary code needed to do local testing.
|
* @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
|
* 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.
|
* @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;
|
$is_external = true;
|
||||||
|
|
||||||
return $is_external;
|
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.
|
* @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.
|
* TODO: remove it.
|
||||||
*/
|
*/
|
||||||
function dont_verify_local_dev_https() {
|
function activitypub_event_extensions_dont_verify_local_dev_https() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @license AGPL-3.0-or-later
|
* @license AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event as Event_Transformer;
|
||||||
use EM_Event;
|
use EM_Event;
|
||||||
use Activitypub\Activity\Extended_Object\Event;
|
use Activitypub\Activity\Extended_Object\Event;
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
* @license AGPL-3.0-or-later
|
* @license AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace Activitypub_Event_Extensions\Activitypub\Transformer;
|
||||||
|
|
||||||
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
use Activitypub_Event_Extensions\Activitypub\Transformer\Event;
|
||||||
use Activitypub\Model\Blog;
|
use Activitypub\Model\Blog;
|
||||||
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
use Activitypub\Activity\Extended_Object\Event as Event_Object;
|
||||||
|
|
|
@ -37,7 +37,7 @@ class Settings_Page {
|
||||||
public static function admin_menu(): void {
|
public static function admin_menu(): void {
|
||||||
\add_options_page(
|
\add_options_page(
|
||||||
'Activitypub Event Extension',
|
'Activitypub Event Extension',
|
||||||
__( 'ActivityPub Events', 'activitypub_event_extensions' ),
|
__( 'ActivityPub Events', 'activitypub-event-extensions' ),
|
||||||
'manage_options',
|
'manage_options',
|
||||||
self::SETTINGS_SLUG,
|
self::SETTINGS_SLUG,
|
||||||
array( self::STATIC, 'settings_page' )
|
array( self::STATIC, 'settings_page' )
|
||||||
|
|
|
@ -76,7 +76,7 @@ $current_category_mapping = \get_option( 'activitypub_event_extensions_ev
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2> <?php esc_html_e( 'Default ActivityPub Event Category', 'activitypub-event-extensions' ); ?> </h2>
|
<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">
|
<table class="form-table">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"> <?php esc_html_e( 'Default Category', 'activitypub-event-extensions' ); ?> </th>
|
<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 ) ) : ?>
|
<?php if ( ! empty( $event_terms ) ) : ?>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<h2> <?php esc_html_e( 'Advanced Event Category Settings', 'activitypub-event-extensions' ); ?> </h2>
|
<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">
|
<table class="form-table">
|
||||||
<?php foreach ( $event_terms as $event_term ) { ?>
|
<?php foreach ( $event_terms as $event_term ) { ?>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Reference in a new issue