Skip to content
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
36 changes: 36 additions & 0 deletions .github/actions/code-quality/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'PHP Code Quality'
description: 'Sets up PHP and runs code quality tools'
inputs:
working-directory:
description: 'Directory to run composer and quality tools in'
required: true
runs:
using: "composite"
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: composer:v2
coverage: none

- name: Install dependencies
uses: ramsey/composer-install@v2
with:
working-directory: ${{ inputs.working-directory }}
composer-options: "--no-progress"

- name: Run PHPStan
working-directory: ${{ inputs.working-directory }}
run: composer run-script phpstan
shell: bash

- name: Run Psalm
working-directory: ${{ inputs.working-directory }}
run: composer run-script php:psalm
shell: bash

- name: Run PHP CodeSniffer
working-directory: ${{ inputs.working-directory }}
run: composer run-script check-cs
shell: bash
27 changes: 27 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Code Quality

on:
pull_request:
paths:
- 'plugins/**'

jobs:
run:
runs-on: ubuntu-latest
name: Check code quality

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get changed plugin directory
id: plugin
run: |
git fetch --prune --unshallow
plugin=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep '^plugins/' | head -1 | cut -d/ -f2)
echo "slug=$plugin" >> $GITHUB_OUTPUT

- name: PHP Code Quality
uses: ./.github/actions/code-quality
with:
working-directory: plugins/${{ steps.plugin.outputs.slug }}
2 changes: 1 addition & 1 deletion plugins/hwp-previews/ACTIONS_AND_FILTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
- `hwp_previews_settings_group_settings_group` - Filter to modify the settings group name. Default is HWP_PREVIEWS_SETTINGS_GROUP
- `hwp_previews_settings_group_settings_config` - Filter to modify the settings array. See `Settings_Group`
- `hwp_previews_settings_group_cache_groups` - Filter to modify cache groups for `Settings_Group`
- `hwp_preview_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
- `hwp_previews_get_post_types_config` - Filter for generating the instance of `Post_Types_Config_Interface`
- `hwp_previews_hooks_post_type_config` - Filter for post type config service for the Hook class
- `hwp_previews_hooks_post_status_config` - Filter for post status config service for the Hook class
- `hwp_previews_hooks_preview_link_service` - Filter for preview link service for the Hook class
Expand Down
8 changes: 4 additions & 4 deletions plugins/hwp-previews/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
},
"archive": {
"name": "hwp-previews",
"name": "hwp-previews",
"exclude": [
"/.*",
"bin",
Expand Down Expand Up @@ -100,9 +100,9 @@
"phpstan": [
"vendor/bin/phpstan analyze --ansi --memory-limit=1G"
],
"psalm": [
"vendor/bin/psalm --no-progress --show-info=false"
]
"php:psalm": "psalm",
"php:psalm:info": "psalm --show-info=true",
"php:psalm:fix": "psalm --alter"
},
"scripts-descriptions": {
},
Expand Down
14 changes: 7 additions & 7 deletions plugins/hwp-previews/composer.lock

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

80 changes: 34 additions & 46 deletions plugins/hwp-previews/hwp-previews.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
* @package HWP\Previews
*/

declare( strict_types=1 );
declare(strict_types=1);

use HWP\Previews\Autoloader;
use HWP\Previews\Plugin;

if ( ! defined( 'ABSPATH' ) ) {
Expand All @@ -29,62 +30,43 @@

// Load the autoloader.
require_once __DIR__ . '/src/Autoloader.php';
if ( ! \HWP\Previews\Autoloader::autoload() ) {
if ( ! Autoloader::autoload() ) {
return;
}

if ( file_exists( __DIR__ . '/activation.php' ) ) {
require_once __DIR__ . '/activation.php';
// @phpstan-ignore-next-line
register_activation_hook( __FILE__, 'hwp_previews_activation_callback' );
}

if ( file_exists( __DIR__ . '/deactivation.php' ) ) {
require_once __DIR__ . '/deactivation.php';
// @phpstan-ignore-next-line
register_deactivation_hook( __FILE__, 'hwp_previews_deactivation_callback' );
}

/**
* Define plugin constants.
*/
function hwp_previews_constants(): void {
// Plugin version.
if ( ! defined( 'HWP_PREVIEWS_VERSION' ) ) {
define( 'HWP_PREVIEWS_VERSION', '0.0.1' );
}

// Plugin Folder Path.
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
define( 'HWP_PREVIEWS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}

// Plugin Folder URL.
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_URL' ) ) {
define( 'HWP_PREVIEWS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}

// Plugin Root File.
if ( ! defined( 'HWP_PREVIEWS_PLUGIN_FILE' ) ) {
define( 'HWP_PREVIEWS_PLUGIN_FILE', __FILE__ );
}

// Whether to autoload the files or not.
if ( ! defined( 'HWP_PREVIEWS_AUTOLOAD' ) ) {
define( 'HWP_PREVIEWS_AUTOLOAD', true );
}

// Text Domain
if ( ! defined( 'HWP_PREVIEWS_TEXT_DOMAIN' ) ) {
define( 'HWP_PREVIEWS_TEXT_DOMAIN', 'hwp-previews' );
}

// Plugin config settings group
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_GROUP' ) ) {
define( 'HWP_PREVIEWS_SETTINGS_GROUP', 'hwp_previews_settings_group' );
}

// Plugin config settings key.
if ( ! defined( 'HWP_PREVIEWS_SETTINGS_KEY' ) ) {
define( 'HWP_PREVIEWS_SETTINGS_KEY', 'hwp_previews_settings' );
$constants = [
'HWP_PREVIEWS_VERSION' => '0.0.1',
'HWP_PREVIEWS_PLUGIN_DIR' => plugin_dir_path( __FILE__ ),
'HWP_PREVIEWS_PLUGIN_URL' => plugin_dir_url( __FILE__ ),
'HWP_PREVIEWS_PLUGIN_FILE' => __FILE__,
'HWP_PREVIEWS_AUTOLOAD' => true,
'HWP_PREVIEWS_SETTINGS_GROUP' => 'hwp_previews_settings_group',
'HWP_PREVIEWS_SETTINGS_KEY' => 'hwp_previews_settings',
'HWP_PREVIEWS_TEXT_DOMAIN' => 'hwp-previews',
];

foreach ( $constants as $name => $value ) {
if ( ! defined( $name ) ) {
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
define( $name, $value );
// phpcs:enable WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
}
}

// Plugin Template Directory.
Expand All @@ -99,7 +81,6 @@ function hwp_previews_constants(): void {
function hwp_previews_init(): void {
hwp_previews_constants();


if ( defined( 'HWP_PREVIEWS_PLUGIN_DIR' ) ) {
require_once HWP_PREVIEWS_PLUGIN_DIR . 'src/Plugin.php';
Plugin::instance();
Expand All @@ -110,14 +91,12 @@ function hwp_previews_init(): void {

add_action(
'admin_notices',
static function () {
static function (): void {
?>
<div class="error notice">
<p>
<?php
printf(
esc_html__( 'Composer vendor directory must be present for HWP Previews to work.', 'hwp-previews' ),
);
echo 'Composer vendor directory must be present for HWP Previews to work.'
?>
</p>
</div>
Expand All @@ -128,5 +107,14 @@ static function () {
);
}

/**
* Load plugin textdomain.
*/
function hwp_previews_load_textdomain(): void {
load_plugin_textdomain( 'hwp-previews', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}

add_action( 'init', 'hwp_previews_load_textdomain', 1, 0 );

/** @psalm-suppress HookNotFound */
add_action( 'plugins_loaded', 'hwp_previews_init', 15 );
add_action( 'plugins_loaded', 'hwp_previews_init', 15, 0 );
5 changes: 3 additions & 2 deletions plugins/hwp-previews/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ parameters:
max: 80400
paths:
- hwp-previews.php
- vendor/autoload.php
- src/
ignoreErrors:
- identifier: empty.notAllowed
-
identifier: empty.notAllowed
message: '#Constant HWP_PREVIEWS.* not found\.#'

22 changes: 18 additions & 4 deletions plugins/hwp-previews/psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,26 @@
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<file name="hwp-previews.php" />
<file name="vendor/autoload.php" />
<file name="hwp-previews.php"/>
<file name="vendor/autoload.php"/>
<directory name="src"/>
</projectFiles>

<plugins>
<pluginClass class="PsalmWordPress\Plugin" />
<pluginClass class="PsalmWordPress\Plugin"/>
</plugins>

<issueHandlers>
<!-- Noting we had issues with trying to set stubs and also using issueHandlers for particular constants-->
<UndefinedConstant errorLevel="suppress">
<errorLevel type="suppress">
<directory name="src"/>
</errorLevel>
</UndefinedConstant>
<InvalidArgument>
<errorLevel type="suppress">
<file name="src/Hooks/Preview_Hooks.php"/>
</errorLevel>
</InvalidArgument>
</issueHandlers>
</psalm>
Loading