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

Housekeeping #321

Merged
merged 17 commits into from
Nov 21, 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
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"wp-coding-standards/wpcs": "dev-develop",
"wp-coding-standards/wpcs": "^3",
"phpcompatibility/php-compatibility": "^9.0",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"phpunit/phpunit": "9.*||10.*",
"phpunit/phpunit": "9.*||10.*||11.*",
"mikey179/vfsstream": "~1",
"brain/monkey": "^2.2",
"roave/security-advisories": "dev-master",
"humbug/php-scoper": "^0.18",
"mundschenk-at/phpunit-cross-version": "dev-master",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan": "^2",
"sniccowp/php-scoper-wordpress-excludes": "^6",
"szepeviktor/phpstan-wordpress": "^1.1",
"szepeviktor/phpstan-wordpress": "^2.0.0-rc.2",
"phpstan/extension-installer": "^1.2",
"paulthewalton/acf-stubs": "^5.8",
"phpstan/phpstan-phpunit": "^1.2"
"phpstan/phpstan-phpunit": "^2",
"phpstan/phpstan-mockery": "^2.0"
},

"minimum-stability": "dev",
Expand Down
40 changes: 16 additions & 24 deletions includes/class-wp-typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2014-2023 Peter Putzer.
* Copyright 2014-2024 Peter Putzer.
* Copyright 2009-2011 KINGdesk, LLC.
*
* This program is free software; you can redistribute it and/or
Expand All @@ -25,15 +25,7 @@
* @license http://www.gnu.org/licenses/gpl-2.0.html
*/

use WP_Typography\Data_Storage\Cache;
use WP_Typography\Data_Storage\Options;
use WP_Typography\Data_Storage\Transients;

use WP_Typography\Settings\Plugin_Configuration as Config;

use PHP_Typography\PHP_Typography;
use PHP_Typography\Settings;
use PHP_Typography\Hyphenator\Cache as Hyphenator_Cache;

/**
* Main wp-Typography plugin class. All WordPress specific code goes here.
Expand All @@ -48,18 +40,18 @@
*
* @method void clear_cache() Retrieves the plugin's default option values.
*
* @method array get_config() Retrieves the plugin configuration.
* @method array get_default_options() Retrieves the plugin's default option values.
* @method array<string,string|int|bool> get_config() Retrieves the plugin configuration.
* @method array<string,string|int|bool> get_default_options() Retrieves the plugin's default option values.
* @method void set_default_options($force_defaults = false) Initializes the options with default values.
*
* @method string process(string $text, bool $is_title = false, bool $force_feed = false, Settings $settings = null) Processes a text fragment.
* @method string process_title($text, Settings $settings = null) Processes a heading text fragment.
* @method string process_feed_title($text, Settings $settings = null) Processes a heading text fragment as part of an RSS feed.
* @method string process_feed($text, $is_title = false, Settings $settings = null) Processes a content text fragment as part of an RSS feed.
* @method array process_title_parts($title_parts, Settings $settings = null) Processes title parts and strips &shy; and zero-width space.
* @method string[] process_title_parts($title_parts, Settings $settings = null) Processes title parts and strips &shy; and zero-width space.
*
* @method array get_hyphenation_languages() Retrieves and caches the list of valid hyphenation languages.
* @method array get_diacritic_languages() Retrieves and caches the list of valid diacritic replacement languages.
* @method array<string,string> get_hyphenation_languages() Retrieves and caches the list of valid hyphenation languages.
* @method array<string,string> get_diacritic_languages() Retrieves and caches the list of valid diacritic replacement languages.
*/
abstract class WP_Typography {

Expand Down Expand Up @@ -99,7 +91,7 @@ public static function set_instance( WP_Typography $instance ): void {
*
* @return WP_Typography
*/
public static function get_instance() {
public static function get_instance(): WP_Typography {
if ( null === self::$instance ) {
throw new BadMethodCallException( 'WP_Typography::get_instance called without prior plugin intialization.' );
}
Expand All @@ -118,11 +110,11 @@ public static function get_instance() {
*
* @return mixed
*/
public static function __callStatic( $name, array $arguments ) {
public static function __callStatic( string $name, array $arguments ) {
if ( \method_exists( self::$instance, $name ) ) {
return self::$instance->$name( ...$arguments );
} else {
throw new BadMethodCallException( "Static method WP_Typography::$name does not exist." );
throw new BadMethodCallException( 'Static method WP_Typography::' . \esc_html( $name ) . ' does not exist.' );
}
}

Expand All @@ -133,7 +125,7 @@ public static function __callStatic( $name, array $arguments ) {
*
* @return Settings
*/
public static function get_user_settings() {
public static function get_user_settings(): Settings {
return clone self::get_instance()->get_settings();
}

Expand All @@ -149,7 +141,7 @@ public static function get_user_settings() {
*
* @return string The processed $text.
*/
public static function filter( $text, Settings $settings = null ) {
public static function filter( string $text, Settings $settings = null ): string {
return self::get_instance()->process( $text, false, false, $settings );
}

Expand All @@ -165,7 +157,7 @@ public static function filter( $text, Settings $settings = null ) {
*
* @return string The processed $text.
*/
public static function filter_title( $text, Settings $settings = null ) {
public static function filter_title( string $text, Settings $settings = null ): string {
return self::get_instance()->process_title( $text, $settings );
}

Expand Down Expand Up @@ -197,7 +189,7 @@ public static function filter_title_parts( array $title_parts, Settings $setting
*
* @return string The processed $text.
*/
public static function filter_feed( $text, Settings $settings = null ) {
public static function filter_feed( string $text, Settings $settings = null ): string {
return self::get_instance()->process_feed( $text, false, $settings );
}

Expand All @@ -213,7 +205,7 @@ public static function filter_feed( $text, Settings $settings = null ) {
*
* @return string The processed $text.
*/
public static function filter_feed_title( $text, Settings $settings = null ) {
public static function filter_feed_title( string $text, Settings $settings = null ): string {
return self::get_instance()->process_feed_title( $text, $settings );
}

Expand All @@ -234,7 +226,7 @@ public static function filter_feed_title( $text, Settings $settings = null ) {
*
* @return string The hashed version (containing as few bytes as possible);
*/
private static function hash_version_string( $version ) {
private static function hash_version_string( $version ): string {
$hash = '';

foreach ( \explode( '.', $version ) as $part ) {
Expand All @@ -251,7 +243,7 @@ private static function hash_version_string( $version ) {
*
* @return string
*/
public function get_version_hash() {
public function get_version_hash(): string {
return self::hash_version_string( self::get_instance()->get_version() );
}
}
11 changes: 5 additions & 6 deletions includes/wp-typography/class-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2017-2023 Peter Putzer.
* Copyright 2017-2024 Peter Putzer.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -36,7 +36,6 @@

use WP_Typography\Integration\Container as Integrations;
use WP_Typography\Settings\Basic_Locale_Settings;
use WP_Typography\Settings\Locale_Settings;

use WP_Typography\Exceptions\Object_Factory_Exception;

Expand All @@ -63,7 +62,7 @@ class Factory extends Dice {
*
* @var Factory
*/
private static $factory;
private static Factory $factory;

/**
* Creates a new instance.
Expand All @@ -86,7 +85,7 @@ final protected function __construct() {
* be created.
*/
public static function get(): self {
if ( ! self::$factory instanceof static ) {
if ( ! isset( self::$factory ) ) {

// Create factory.
$factory = new static();
Expand Down Expand Up @@ -249,7 +248,7 @@ protected function get_rules(): array {
protected function get_plugin_version( $plugin_file ): string {
// Load version from plugin data.
if ( ! \function_exists( 'get_plugin_data' ) ) {
require_once \ABSPATH . 'wp-admin/includes/plugin.php';
require_once \ABSPATH . 'wp-admin/includes/plugin.php'; // @phpstan-ignore requireOnce.fileNotFound
}

return \get_plugin_data( $plugin_file, false, false )['Version'];
Expand Down Expand Up @@ -318,7 +317,7 @@ protected function get_plugin_integrations(): array {
* }
* }
*
* @phpstan-return array<array<self::INSTANCE,string>>>
* @phpstan-return array<array<self::INSTANCE,string>>
*/
protected function get_supported_locales(): array {
return [
Expand Down
7 changes: 3 additions & 4 deletions includes/wp-typography/class-implementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2014-2023 Peter Putzer.
* Copyright 2014-2024 Peter Putzer.
* Copyright 2009-2011 KINGdesk, LLC.
*
* This program is free software; you can redistribute it and/or
Expand Down Expand Up @@ -222,7 +222,7 @@ protected function load_languages( $cache_key, callable $get_language_list, $typ
private static function translate_languages( array $languages ): array {
\array_walk(
$languages,
function( &$lang ) {
function ( &$lang ) {
// The language names are made visible to GlotPress via the
// autogenerated source file `_language_names.php` (which is not
// actually included anywhere).
Expand Down Expand Up @@ -728,7 +728,6 @@ protected function prepare_smart_quotes_exceptions( $custom_exceptions ): array
)
);

// @phpstan-ignore-next-line -- Ternary condition is not always true on PHP 7.4.
$exceptions = \array_combine( $patterns, $replacements ) ?: []; // phpcs:ignore Universal.Operators.DisallowShortTernary -- ensure array type.
}

Expand All @@ -741,7 +740,7 @@ protected function prepare_smart_quotes_exceptions( $custom_exceptions ): array
// Longest strings first.
\uksort(
$exceptions,
function( $a, $b ) {
function ( $a, $b ) {
return ( \strlen( $b ) - \strlen( $a ) ) ?: \strcmp( $a, $b ); // phpcs:ignore Universal.Operators.DisallowShortTernary
}
);
Expand Down
7 changes: 3 additions & 4 deletions includes/wp-typography/class-plugin-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace WP_Typography;

use WP_Typography\Implementation;
use WP_Typography\Components\Plugin_Component;

/**
Expand All @@ -40,16 +39,16 @@ class Plugin_Controller {
/**
* The plugin API implementation.
*
* @var \WP_Typography\Implementation
* @var \WP_Typography
*/
private $api;
private \WP_Typography $api;

/**
* The plugin components in order of execution.
*
* @var Plugin_Component[]
*/
private $plugin_components = [];
private array $plugin_components = [];

/**
* Sets up a new plugin controller instance.
Expand Down
4 changes: 2 additions & 2 deletions includes/wp-typography/class-requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2020-2023 Peter Putzer.
* Copyright 2020-2024 Peter Putzer.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -39,7 +39,7 @@
class Requirements extends \Mundschenk\WP_Requirements {

const REQUIREMENTS = [
'php' => '7.2.0',
'php' => '7.4.0',
'multibyte' => true,
'utf-8' => true,
'dom' => true,
Expand Down
22 changes: 11 additions & 11 deletions includes/wp-typography/components/class-admin-interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2014-2023 Peter Putzer.
* Copyright 2014-2024 Peter Putzer.
* Copyright 2012-2013 Marie Hogebrandt.
* Copyright 2009-2011 KINGdesk, LLC.
*
Expand Down Expand Up @@ -71,7 +71,7 @@ class Admin_Interface implements Plugin_Component {
*
* @var Options
*/
private $options;
private Options $options;

/**
* The template helper.
Expand All @@ -85,21 +85,21 @@ class Admin_Interface implements Plugin_Component {
*
* @var string $plugin_name
*/
private $plugin_name = 'wp-Typography';
private string $plugin_name = 'wp-Typography';

/**
* The result of plugin_basename() for the main plugin file (relative from plugins folder).
*
* @var string
*/
private $plugin_basename;
private string $plugin_basename;

/**
* Links to add the settings page.
*
* @var array<string,string> $admin_resource_links An array in the form of 'anchor text' => 'URL'.
*/
private $admin_resource_links;
private array $admin_resource_links;

/**
* Context sensitive help for the settings page.
Expand Down Expand Up @@ -147,7 +147,7 @@ class Admin_Interface implements Plugin_Component {
*
* @var string
*/
private $active_tab;
private string $active_tab;

/**
* The plugin configuration defaults (including UI definition).
Expand All @@ -166,9 +166,9 @@ class Admin_Interface implements Plugin_Component {
/**
* Create a new instace of admin backend.
*
* @since 5.6.0 Parameters $basename and $plugin_path removed.
* @since 5.7.0 Parameter $api added.
* @since 5.9.2 Parameter $template added.
* @since 5.6.0 Parameters $basename and $plugin_path removed.
* @since 5.7.0 Parameter $api added.
* @since 5.10.0 Parameter $template added.
*
* @param Implementation $api The core API.
* @param Options $options The Options API handler.
Expand Down Expand Up @@ -328,7 +328,7 @@ protected function get_active_settings_tab(): string {
*
* @return bool
*/
public function sanitize_restore_defaults( $input ) {
public function sanitize_restore_defaults( $input ): bool {
return $this->trigger_admin_notice( Options::RESTORE_DEFAULTS, 'defaults-restored', \__( 'Settings reset to default values.', 'wp-typography' ), 'updated', $input );
}

Expand Down Expand Up @@ -516,7 +516,7 @@ public function get_admin_page_content(): void {
* Loads the available language option values into the control.
*
* @since 5.9.0
* @since 5.9.2 Visibility changed to `protected`.
* @since 5.10.0 Visibility changed to `protected`.
*
* @param Control $control The UI control (needs to be a Select element).
* @param array<string,string> $languages The list of available language choices (in the form `$code => $translated_name`).
Expand Down
4 changes: 2 additions & 2 deletions includes/wp-typography/components/class-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of wp-Typography.
*
* Copyright 2020-2023 Peter Putzer.
* Copyright 2020-2024 Peter Putzer.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -77,7 +77,7 @@ public function register_sidebar_and_blocks(): void {

// Register the script containing all our block types (and the sidebar plugin).
$blocks = 'admin/block-editor/js/index';
$asset = include \WP_TYPOGRAPHY_PLUGIN_PATH . "/{$blocks}.asset.php";
$asset = include \WP_TYPOGRAPHY_PLUGIN_PATH . "/{$blocks}.asset.php"; // @phpstan-ignore include.fileNotFound
\wp_register_script( 'wp-typography-gutenberg', "{$plugin_url}/{$blocks}.js", $asset['dependencies'], $asset['version'], false );
\wp_register_style( 'wp-typography-gutenberg-style', "{$plugin_url}/admin/css/blocks{$suffix}.css", [], $this->api->get_version() );

Expand Down
Loading
Loading