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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"phpmd/phpmd": "^2.15",
"phpro/grumphp": "^2.15",
"phpunit/phpunit": "^9.6",
"rector/rector": "^2.2",
"rregeer/phpunit-coverage-check": "^0.3.1",
"squizlabs/php_codesniffer": "^3.9.2",
"symfony/css-selector": "^7.3",
Expand Down Expand Up @@ -81,4 +82,4 @@
"wp:i18n:make-mo": "wp i18n make-mo ./languages",
"wp:i18n:make-pot": "wp i18n make-pot ./ languages/speechkit.pot --slug=speechkit"
}
}
}
115 changes: 114 additions & 1 deletion composer.lock

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

1 change: 1 addition & 0 deletions doc/code-quality-checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The checks are:
using the config at `phpcs.xml`, to *PSR-12* and *WordPress VIP* standards.
- `phplint`: Check source files for syntax errors
- `phpmd`: Check source files for bad coding standards
- `rector`: Check source files for refactoring opportunities
- `test_phpunit`: PHPUnit tests
- `coverage_check`: PHPUnit code coverage

Expand Down
13 changes: 13 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ grumphp:
- vendor
metadata:
priority: 10
rector:
config: rector.php
triggered_by:
- php
ignore_patterns:
- /tests/*
- /vendor/*
clear_cache: false
no_diffs: false
metadata:
priority: 10
test_phpunit:
script: test:phpunit
metadata:
Expand All @@ -77,10 +88,12 @@ grumphp:
- phpcs
- phplint
- phpmd
- rector
code_quality:
tasks:
- composer
- composer_normalize
- phpcs
- phplint
- phpmd
- rector
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
"lint:pkg-json": "wp-scripts lint-pkg-json",
"mockoon:start": "mockoon-cli start --data ./.mockoon/beyondwords-api.json --port 3000",
"packages-update": "wp-scripts packages-update",
"rector": "wp-env run cli --env-cwd=/var/www/html/wp-content/plugins/speechkit ./vendor/bin/rector process --dry-run",
"rector:fix": "wp-env run cli --env-cwd=/var/www/html/wp-content/plugins/speechkit ./vendor/bin/rector process",
"rector:fix:diff": "wp-env run cli --env-cwd=/var/www/html/wp-content/plugins/speechkit ./vendor/bin/rector process --debug",
"start": "wp-scripts start",
"test:e2e": "wp-scripts test-e2e",
"test:unit": "wp-scripts test-unit-js",
Expand Down
31 changes: 31 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/index.php',
__DIR__ . '/speechkit.php',
__DIR__ . '/uninstall.php',
])
->withSkip([
__DIR__ . '/tests',
__DIR__ . '/vendor',
])
->withRules([
// Add any additional rules here.
])
->withPreparedSets(
deadCode: true, // Remove dead code
codeQuality: false, // Don't auto-refactor code quality (too aggressive for WordPress)
)
->withPhpSets(
php80: true // Use PHP 8.0 features
)
->withTypeCoverageLevel(0); // Don't enforce type coverage (just clean up)
2 changes: 1 addition & 1 deletion src/Compatibility/WPGraphQL/WPGraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class WPGraphQL
public static function init()
{
// Actions for WPGraphQL
add_action('graphql_register_types', array(__CLASS__, 'graphqlRegisterTypes'));
add_action('graphql_register_types', [self::class, 'graphqlRegisterTypes']);
}

/**
Expand Down
36 changes: 16 additions & 20 deletions src/Component/Post/AddPlayer/AddPlayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class AddPlayer
*/
public static function init()
{
add_action('init', array(__CLASS__, 'registerBlock'));
add_action('enqueue_block_editor_assets', array(__CLASS__, 'addBlockEditorStylesheet'));
add_action('init', [self::class, 'registerBlock']);
add_action('enqueue_block_editor_assets', [self::class, 'addBlockEditorStylesheet']);

add_action('admin_head', array(__CLASS__, 'addEditorStyles'));
add_filter('tiny_mce_before_init', array(__CLASS__, 'filterTinyMceSettings'));
add_action('admin_head', [self::class, 'addEditorStyles']);
add_filter('tiny_mce_before_init', [self::class, 'filterTinyMceSettings']);

add_filter('mce_external_plugins', array(__CLASS__, 'addPlugin'));
add_filter('mce_buttons', array(__CLASS__, 'addButton'));
add_filter('mce_css', array(__CLASS__, 'addStylesheet'));
add_filter('mce_external_plugins', [self::class, 'addPlugin']);
add_filter('mce_buttons', [self::class, 'addButton']);
add_filter('mce_css', [self::class, 'addStylesheet']);
}

/**
Expand All @@ -60,10 +60,8 @@ public static function registerBlock()
* @since 6.0.0 Make static.
*
* @param array TinyMCE plugin array
*
* @return array
*/
public static function addPlugin($plugin_array)
public static function addPlugin(array $plugin_array): array
{
$plugin_array['beyondwords_player'] = BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/AddPlayer/tinymce.js';
return $plugin_array;
Expand All @@ -75,10 +73,8 @@ public static function addPlugin($plugin_array)
* @since 6.0.0 Make static.
*
* @param array TinyMCE buttons array
*
* @return array
*/
public static function addButton($buttons)
public static function addButton(array $buttons): array
{
$advIndex = array_search('wp_adv', $buttons);

Expand All @@ -100,7 +96,7 @@ public static function addButton($buttons)
*
* @return string Comma-delimited list of stylesheets with the "Add Player" CSS appended.
*/
public static function addStylesheet($stylesheets)
public static function addStylesheet(string $stylesheets): string
{
return $stylesheets . ',' . BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/AddPlayer/AddPlayer.css';
}
Expand Down Expand Up @@ -135,7 +131,7 @@ public static function playerPreviewI18nStyles()
*
* @return mixed[] An array with TinyMCE config.
*/
public static function filterTinyMceSettings($settings)
public static function filterTinyMceSettings(array $settings): array
{
if (isset($settings['content_style'])) {
$settings['content_style'] .= ' ' . self::playerPreviewI18nStyles() . ' ';
Expand All @@ -156,9 +152,9 @@ public static function filterTinyMceSettings($settings)
*/
public static function addEditorStyles()
{
$allowed_html = array(
'style' => array(),
);
$allowed_html = [
'style' => [],
];

echo wp_kses(
sprintf('<style>%s</style>', self::playerPreviewI18nStyles()),
Expand All @@ -171,15 +167,15 @@ public static function addEditorStyles()
*
* @since 6.0.0 Make static.
*/
public static function addBlockEditorStylesheet($hook)
public static function addBlockEditorStylesheet(string $hook): void
{
// Only enqueue for Gutenberg/Post screens
if (CoreUtils::isGutenbergPage() || $hook === 'post.php' || $hook === 'post-new.php') {
// Register the Classic/Block Editor "Add Player" CSS
wp_enqueue_style(
'beyondwords-AddPlayer',
BEYONDWORDS__PLUGIN_URI . 'src/Component/Post/AddPlayer/AddPlayer.css',
array(),
[],
BEYONDWORDS__PLUGIN_VERSION
);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Component/Post/BlockAttributes/BlockAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class BlockAttributes
*/
public static function init()
{
add_filter('register_block_type_args', array(__CLASS__, 'registerAudioAttribute'));
add_filter('register_block_type_args', array(__CLASS__, 'registerMarkerAttribute'));
add_filter('render_block', array(__CLASS__, 'renderBlock'), 10, 2);
add_filter('register_block_type_args', [self::class, 'registerAudioAttribute']);
add_filter('register_block_type_args', [self::class, 'registerMarkerAttribute']);
add_filter('render_block', [self::class, 'renderBlock'], 10, 2);
}

/**
Expand All @@ -47,14 +47,14 @@ public static function registerAudioAttribute($args)
{
// Setup attributes if needed.
if (! isset($args['attributes'])) {
$args['attributes'] = array();
$args['attributes'] = [];
}

if (! array_key_exists('beyondwordsAudio', $args['attributes'])) {
$args['attributes']['beyondwordsAudio'] = array(
$args['attributes']['beyondwordsAudio'] = [
'type' => 'boolean',
'default' => true,
);
];
}

return $args;
Expand All @@ -69,14 +69,14 @@ public static function registerMarkerAttribute($args)
{
// Setup attributes if needed.
if (! isset($args['attributes'])) {
$args['attributes'] = array();
$args['attributes'] = [];
}

if (! array_key_exists('beyondwordsMarker', $args['attributes'])) {
$args['attributes']['beyondwordsMarker'] = array(
$args['attributes']['beyondwordsMarker'] = [
'type' => 'string',
'default' => '',
);
];
}

return $args;
Expand Down
Loading