Skip to content

Commit

Permalink
Upgrade code to PHP 7.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Nov 13, 2024
1 parent c3bafcf commit e9e9203
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/php/ACF.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct( Settings $settings ) {
/**
* Init class hooks.
*/
public function init_hooks() {
public function init_hooks(): void {
add_action( 'acf/field_group/admin_enqueue_scripts', [ $this, 'enqueue_script' ] );
}

Expand All @@ -44,7 +44,7 @@ public function init_hooks() {
*
* @return void
*/
public function enqueue_script() {
public function enqueue_script(): void {
global $cyr_to_lat_plugin;

$min = $cyr_to_lat_plugin->min_suffix();
Expand Down
4 changes: 2 additions & 2 deletions src/php/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct() {
* is-dismissible.
* @param array $options Notice options.
*/
public function add_notice( string $message, string $class_name = 'notice', array $options = [] ) {
public function add_notice( string $message, string $class_name = 'notice', array $options = [] ): void {
$this->notices[] = [
'message' => $message,
'class' => $class_name,
Expand All @@ -49,7 +49,7 @@ public function add_notice( string $message, string $class_name = 'notice', arra
*
* @return void
*/
public function show_notices() {
public function show_notices(): void {
foreach ( $this->notices as $notice ) {
if ( ! $this->is_screen_allowed( $notice ) ) {
continue;
Expand Down
3 changes: 3 additions & 0 deletions src/php/ConversionTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @package cyr-to-lat
*/

// phpcs:ignore Generic.Commenting.DocComment.MissingShort
/** @noinspection PhpInternalEntityUsedInspection */

namespace CyrToLat;

use CyrToLat\Symfony\Polyfill\Mbstring\Mbstring;
Expand Down
20 changes: 10 additions & 10 deletions src/php/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Converter {
/**
* Query arg in url to start conversion.
*/
const QUERY_ARG = 'cyr-to-lat-convert';
public const QUERY_ARG = 'cyr-to-lat-convert';

/**
* Regex of allowed chars in lower-cased slugs.
Expand All @@ -31,7 +31,7 @@ class Converter {
*
* @link https://dev.mysql.com/doc/refman/5.6/en/regexp.html
*/
const ALLOWED_CHARS_REGEX = "^([a-z0-9\'-._]|%[2-7][0-F])+$";
public const ALLOWED_CHARS_REGEX = "^([a-z0-9\'-._]|%[2-7][0-F])+$";

/**
* Plugin main class.
Expand Down Expand Up @@ -90,7 +90,7 @@ public function __construct( Main $main, Settings $settings, PostConversionProce
/**
* Init class hooks.
*/
public function init_hooks() {
public function init_hooks(): void {
add_action( 'admin_init', [ $this, 'process_handler' ] );
add_action( 'admin_init', [ $this, 'conversion_notices' ] );
}
Expand All @@ -100,7 +100,7 @@ public function init_hooks() {
*
* @return void
*/
public function conversion_notices() {
public function conversion_notices(): void {
$posts_process_running = $this->process_all_posts->is_processing();
$terms_process_running = $this->process_all_terms->is_processing();

Expand Down Expand Up @@ -142,7 +142,7 @@ public function conversion_notices() {
*
* @return void
*/
public function start_conversion() {
public function start_conversion(): void {
if ( ! isset( $_POST['ctl-convert'] ) ) {
return;
}
Expand All @@ -155,7 +155,7 @@ public function start_conversion() {
*
* @return void
*/
public function process_handler() {
public function process_handler(): void {
if ( ! isset( $_GET[ self::QUERY_ARG ], $_GET['_wpnonce'] ) ) {
return;
}
Expand All @@ -172,7 +172,7 @@ public function process_handler() {
*
* @param array $args Arguments for query.
*/
public function convert_existing_slugs( array $args = [] ) {
public function convert_existing_slugs( array $args = [] ): void {
$this->convert_existing_post_slugs( $args );
$this->convert_existing_term_slugs();
}
Expand All @@ -182,7 +182,7 @@ public function convert_existing_slugs( array $args = [] ) {
*
* @param array $args Arguments for query.
*/
protected function convert_existing_post_slugs( array $args = [] ) {
protected function convert_existing_post_slugs( array $args = [] ): void {
global $wpdb;

$post_types = array_intersect(
Expand Down Expand Up @@ -245,7 +245,7 @@ protected function convert_existing_post_slugs( array $args = [] ) {
/**
* Convert existing term slugs.
*/
protected function convert_existing_term_slugs() {
protected function convert_existing_term_slugs(): void {
global $wpdb;

// phpcs:ignore WordPress.DB.DirectDatabaseQuery
Expand Down Expand Up @@ -286,7 +286,7 @@ protected function convert_existing_term_slugs() {
*
* @noinspection ForgottenDebugOutputInspection
*/
protected function log( string $message ) {
protected function log( string $message ): void {
if ( defined( 'WP_DEBUG_LOG' ) && constant( 'WP_DEBUG_LOG' ) ) {
// @phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( 'Cyr To Lat: ' . $message );
Expand Down
28 changes: 15 additions & 13 deletions src/php/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class Main {
*
* @return void
*/
public function init() {
public function init(): void {
add_action( 'plugins_loaded', [ $this, 'init_all' ], - PHP_INT_MAX );
}

Expand All @@ -145,7 +145,7 @@ public function init() {
*
* @return void
*/
public function init_all() {
public function init_all(): void {
$this->load_textdomain();

$this->init_multilingual();
Expand All @@ -159,7 +159,7 @@ public function init_all() {
*
* @return void
*/
public function load_textdomain() {
public function load_textdomain(): void {
add_filter( 'doing_it_wrong_trigger_error', [ $this, 'doing_it_wrong_trigger_error' ], 10, 4 );

load_default_textdomain();
Expand All @@ -176,7 +176,7 @@ public function load_textdomain() {
*
* @return void
*/
protected function init_multilingual() {
protected function init_multilingual(): void {
if ( class_exists( Polylang::class ) ) {
add_filter( 'locale', [ $this, 'pll_locale_filter' ] );
}
Expand All @@ -201,6 +201,7 @@ protected function init_multilingual() {
* @param string $version The version of WordPress where the message was added.
*
* @return bool
* @noinspection PhpUnusedParameterInspection
*/
public function doing_it_wrong_trigger_error( $trigger, string $function_name, string $message, string $version ): bool {

Expand All @@ -216,7 +217,7 @@ public function doing_it_wrong_trigger_error( $trigger, string $function_name, s
*
* @return void
*/
public function init_classes() {
public function init_classes(): void {
$this->request = new Request();
$this->settings = new Settings(
[
Expand Down Expand Up @@ -254,7 +255,7 @@ public function init_classes() {
*
* @return void
*/
protected function init_cli() {
protected function init_cli(): void {
if ( ! $this->request->is_cli() ) {
return;
}
Expand All @@ -276,7 +277,7 @@ protected function init_cli() {
/**
* Init hooks.
*/
protected function init_hooks() {
protected function init_hooks(): void {
if ( $this->is_frontend ) {
add_action( 'woocommerce_before_template_part', [ $this, 'woocommerce_before_template_part_filter' ] );
add_action( 'woocommerce_after_template_part', [ $this, 'woocommerce_after_template_part_filter' ] );
Expand Down Expand Up @@ -382,7 +383,7 @@ public function sanitize_title( $title, $raw_title = '', $context = '' ) {
*
* @return void
*/
public function woocommerce_before_template_part_filter() {
public function woocommerce_before_template_part_filter(): void {
add_filter( 'sanitize_title', [ $this, 'sanitize_title' ], 9, 3 );
}

Expand All @@ -392,7 +393,7 @@ public function woocommerce_before_template_part_filter() {
*
* @return void
*/
public function woocommerce_after_template_part_filter() {
public function woocommerce_after_template_part_filter(): void {
remove_filter( 'sanitize_title', [ $this, 'sanitize_title' ], 9 );
}

Expand Down Expand Up @@ -821,7 +822,7 @@ public function wpml_locale_filter( $locale ) {
* @return string|null
* @noinspection PhpUndefinedFunctionInspection
*/
protected function get_wpml_locale() {
protected function get_wpml_locale(): ?string {
$language_code = wpml_get_current_language();
$this->wpml_languages = (array) apply_filters( 'wpml_active_languages', [] );

Expand All @@ -843,7 +844,7 @@ protected function get_wpml_locale() {
* @noinspection PhpUnusedParameterInspection
* @noinspection PhpMissingParamTypeInspection
*/
public function wpml_language_has_switched( $language_code, $cookie_lang, string $original_language ) {
public function wpml_language_has_switched( $language_code, $cookie_lang, string $original_language ): void {
$language_code = (string) $language_code;

$this->wpml_locale =
Expand All @@ -860,8 +861,9 @@ public function wpml_language_has_switched( $language_code, $cookie_lang, string
* @param WP_Post $post_before The previous post object.
*
* @noinspection PhpMissingParamTypeInspection
* @noinspection PhpUnusedParameterInspection
*/
public function check_for_changed_slugs( $post_id, $post, $post_before ) {
public function check_for_changed_slugs( $post_id, $post, $post_before ): void {
// Don't bother if it hasn't changed.
if ( $post->post_name === $post_before->post_name ) {
return;
Expand All @@ -887,7 +889,7 @@ public function check_for_changed_slugs( $post_id, $post, $post_before ) {
*
* @return void
*/
public function declare_wc_compatibility() {
public function declare_wc_compatibility(): void {
if ( class_exists( FeaturesUtil::class ) ) {
FeaturesUtil::declare_compatibility(
'custom_order_tables',
Expand Down
6 changes: 3 additions & 3 deletions src/php/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function are_requirements_met(): bool {
/**
* Deactivate plugin.
*/
public function deactivate_plugin() {
public function deactivate_plugin(): void {
if ( is_plugin_active( plugin_basename( constant( 'CYR_TO_LAT_FILE' ) ) ) ) {
deactivate_plugins( plugin_basename( constant( 'CYR_TO_LAT_FILE' ) ) );
// phpcs:disable WordPress.Security.NonceVerification.Recommended
Expand Down Expand Up @@ -190,7 +190,7 @@ private function is_max_input_vars_required(): bool {
/**
* Try to fix max_input_vars.
*/
protected function try_to_fix_max_input_vars() {
protected function try_to_fix_max_input_vars(): void {
$user_ini_filename = $this->get_user_ini_filename();

$content = $this->wp_filesystem->get_contents( $user_ini_filename );
Expand Down Expand Up @@ -238,7 +238,7 @@ private function get_user_ini_filename(): string {
/**
* Asl user to increase max_input_vars.
*/
private function ask_to_increase_max_input_vars() {
private function ask_to_increase_max_input_vars(): void {
$message = __( 'Please increase max input vars limit up to 1500.', 'cyr2lat' );

$message .= '<br>';
Expand Down
2 changes: 1 addition & 1 deletion src/php/WPCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct( Converter $converter ) {
*
* @noinspection PhpUnusedParameterInspection
*/
public function regenerate( array $args = [], array $assoc_args = [] ) {
public function regenerate( array $args = [], array $assoc_args = [] ): void {

/**
* Notify instance.
Expand Down

0 comments on commit e9e9203

Please sign in to comment.