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 e9e9203 commit 6cdf8f4
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/php/BackgroundProcesses/ConversionProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function is_process_completed(): bool {
*
* @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
10 changes: 6 additions & 4 deletions src/php/BackgroundProcesses/PostConversionProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function task( $post ): bool {
*
* @param int $post_id Post ID.
*/
protected function rename_attachment( int $post_id ) {
protected function rename_attachment( int $post_id ): void {
$file = get_attached_file( $post_id );

if ( $file ) {
Expand All @@ -114,7 +114,7 @@ protected function rename_attachment( int $post_id ) {
*
* @param int $post_id Post ID.
*/
protected function rename_thumbnails( int $post_id ) {
protected function rename_thumbnails( int $post_id ): void {
$sizes = get_intermediate_image_sizes();

foreach ( $sizes as $size ) {
Expand All @@ -137,7 +137,7 @@ protected function rename_thumbnails( int $post_id ) {
*
* @param int $attachment_id Attachment ID.
*/
protected function update_attachment_metadata( int $attachment_id ) {
protected function update_attachment_metadata( int $attachment_id ): void {
$meta = wp_get_attachment_metadata( $attachment_id );

if ( isset( $meta['file'] ) ) {
Expand Down Expand Up @@ -176,7 +176,7 @@ protected function get_transliterated_file( string $file ): string {
*
* @return bool|null
*/
protected function rename_file( string $file, string $new_file ) {
protected function rename_file( string $file, string $new_file ): ?bool {
$path = pathinfo( $file );
$new_path = pathinfo( $new_file );

Expand All @@ -193,6 +193,8 @@ protected function rename_file( string $file, string $new_file ) {

/**
* Complete
*
* @noinspection ReturnTypeCanBeDeclaredInspection
*/
protected function complete() {
parent::complete();
Expand Down
2 changes: 2 additions & 0 deletions src/php/BackgroundProcesses/TermConversionProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ protected function task( $term ) {

/**
* Complete
*
* @noinspection ReturnTypeCanBeDeclaredInspection
*/
protected function complete() {
parent::complete();
Expand Down
64 changes: 34 additions & 30 deletions src/php/Settings/Abstracts/SettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ abstract class SettingsBase {
/**
* Admin script handle.
*/
const HANDLE = 'ctl-settings-base';
public const HANDLE = 'ctl-settings-base';

/**
* Network-wide option suffix.
*/
const NETWORK_WIDE = '_network_wide';
public const NETWORK_WIDE = '_network_wide';

/**
* Form fields.
Expand Down Expand Up @@ -148,7 +148,7 @@ abstract protected function section_title(): string;
*
* @param array $arguments Arguments.
*/
abstract public function section_callback( array $arguments );
abstract public function section_callback( array $arguments ): void;

/**
* Get text domain.
Expand Down Expand Up @@ -178,7 +178,7 @@ public function __construct( $tabs = [] ) {
/**
* Init class.
*/
public function init() {
public function init(): void {
$this->min_prefix = defined( 'SCRIPT_DEBUG' ) && constant( 'SCRIPT_DEBUG' ) ? '' : '.min';

$this->form_fields();
Expand All @@ -192,7 +192,7 @@ public function init() {
/**
* Init class hooks.
*/
protected function init_hooks() {
protected function init_hooks(): void {
add_action( 'plugins_loaded', [ $this, 'load_plugin_textdomain' ] );

add_filter(
Expand All @@ -212,7 +212,7 @@ protected function init_hooks() {
/**
* Init form fields.
*/
public function init_form_fields() {
public function init_form_fields(): void {
$this->form_fields = [];
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public function add_settings_link( $actions ): array {
* and make sure the $settings array is either the default
* or the settings stored in the database.
*/
protected function init_settings() {
protected function init_settings(): void {
$network_wide = get_site_option( $this->option_name() . self::NETWORK_WIDE, [] );

if ( empty( $network_wide ) ) {
Expand Down Expand Up @@ -372,7 +372,7 @@ protected function form_fields(): array {
* @return void
* @noinspection PhpUnusedParameterInspection
*/
protected function set_defaults( array &$field, string $id ) {
protected function set_defaults( array &$field, string $id ): void {
$field = wp_parse_args(
$field,
[
Expand All @@ -391,7 +391,7 @@ protected function set_defaults( array &$field, string $id ) {
*
* @return void
*/
public function add_settings_page() {
public function add_settings_page(): void {
if ( $this->is_main_menu_page() ) {
add_menu_page(
$this->page_title(),
Expand All @@ -417,7 +417,7 @@ public function add_settings_page() {
/**
* Invoke relevant settings_page() basing on tabs.
*/
public function settings_base_page() {
public function settings_base_page(): void {
echo '<div class="wrap">';

$this->get_active_tab()->settings_page();
Expand All @@ -428,7 +428,7 @@ public function settings_base_page() {
/**
* Enqueue scripts in admin.
*/
public function admin_enqueue_scripts() {
public function admin_enqueue_scripts(): void {
}

/**
Expand All @@ -437,7 +437,7 @@ public function admin_enqueue_scripts() {
*
* @return void
*/
public function base_admin_enqueue_scripts() {
public function base_admin_enqueue_scripts(): void {
if ( ! $this->is_options_screen() ) {
return;
}
Expand All @@ -457,7 +457,7 @@ public function base_admin_enqueue_scripts() {
*
* @return void
*/
public function setup_sections() {
public function setup_sections(): void {
if ( ! $this->is_options_screen() ) {
return;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ public function setup_sections() {
*
* @return void
*/
public function setup_tabs_section() {
public function setup_tabs_section(): void {
if ( ! $this->is_options_screen() ) {
return;
}
Expand All @@ -508,7 +508,7 @@ public function setup_tabs_section() {
/**
* Show tabs.
*/
public function tabs_callback() {
public function tabs_callback(): void {
?>
<div class="ctl-settings-tabs">
<?php
Expand All @@ -527,7 +527,7 @@ public function tabs_callback() {
*
* @param SettingsBase $tab Tabs of the current settings page.
*/
private function tab_link( SettingsBase $tab ) {
private function tab_link( SettingsBase $tab ): void {
$url = menu_page_url( $this->option_page(), false );
$url = add_query_arg( 'tab', strtolower( $tab->get_class_name() ), $url );
$active = $this->is_tab_active( $tab ) ? ' active' : '';
Expand Down Expand Up @@ -637,7 +637,7 @@ protected function get_active_tab(): SettingsBase {
*
* @return void
*/
public function setup_fields() {
public function setup_fields(): void {
if ( ! $this->is_options_screen() ) {
return;
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public function setup_fields() {
*
* @noinspection PhpUnusedPrivateMethodInspection
*/
private function print_text_field( array $arguments ) {
private function print_text_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );
$autocomplete = '';
$lp_ignore = 'false';
Expand Down Expand Up @@ -696,7 +696,7 @@ private function print_text_field( array $arguments ) {
*
* @noinspection PhpUnusedPrivateMethodInspection
*/
private function print_number_field( array $arguments ) {
private function print_number_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );
$min = $arguments['min'];
$max = $arguments['max'];
Expand All @@ -723,8 +723,9 @@ private function print_number_field( array $arguments ) {
* @param array $arguments Field arguments.
*
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
*/
private function print_textarea_field( array $arguments ) {
private function print_textarea_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );

printf(
Expand All @@ -744,8 +745,9 @@ private function print_textarea_field( array $arguments ) {
*
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
* @noinspection HtmlWrongAttributeValue
*/
private function print_checkbox_field( array $arguments ) {
private function print_checkbox_field( array $arguments ): void {
$value = (array) $this->get( $arguments['field_id'] );

if ( empty( $arguments['options'] ) || ! is_array( $arguments['options'] ) ) {
Expand Down Expand Up @@ -810,8 +812,9 @@ private function print_checkbox_field( array $arguments ) {
*
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
* @noinspection HtmlWrongAttributeValue
*/
private function print_radio_field( array $arguments ) {
private function print_radio_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );

if ( empty( $arguments['options'] ) || ! is_array( $arguments['options'] ) ) {
Expand Down Expand Up @@ -877,7 +880,7 @@ private function print_radio_field( array $arguments ) {
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
*/
private function print_select_field( array $arguments ) {
private function print_select_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );

if ( empty( $arguments['options'] ) || ! is_array( $arguments['options'] ) ) {
Expand Down Expand Up @@ -928,7 +931,7 @@ private function print_select_field( array $arguments ) {
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
*/
private function print_multiple_select_field( array $arguments ) {
private function print_multiple_select_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );

if ( empty( $arguments['options'] ) || ! is_array( $arguments['options'] ) ) {
Expand Down Expand Up @@ -983,8 +986,9 @@ private function print_multiple_select_field( array $arguments ) {
* @param array $arguments Field arguments.
*
* @noinspection PhpUnusedPrivateMethodInspection
* @noinspection HtmlUnknownAttribute
*/
private function print_table_field( array $arguments ) {
private function print_table_field( array $arguments ): void {
$value = $this->get( $arguments['field_id'] );

if ( ! is_array( $value ) ) {
Expand Down Expand Up @@ -1031,7 +1035,7 @@ private function print_table_field( array $arguments ) {
*
* @param array $arguments Field arguments.
*/
public function field_callback( array $arguments ) {
public function field_callback( array $arguments ): void {
if ( empty( $arguments['field_id'] ) ) {
return;
}
Expand Down Expand Up @@ -1138,7 +1142,7 @@ public function set_field( string $key, string $field_key, $value ): bool {
* @param string $key Setting name.
* @param mixed $value Setting value.
*/
public function update_option( string $key, $value ) {
public function update_option( string $key, $value ): void {
if ( empty( $this->settings ) ) {
$this->init_settings();
}
Expand Down Expand Up @@ -1194,7 +1198,7 @@ public function pre_update_option_filter( $value, $old_value ) {
*
* @return void
*/
public function load_plugin_textdomain() {
public function load_plugin_textdomain(): void {
load_plugin_textdomain(
$this->text_domain(),
false,
Expand Down Expand Up @@ -1238,7 +1242,7 @@ protected function is_options_screen( $ids = 'options' ): bool {
*
* @return void
*/
private function print_helper( string $helper ) {
private function print_helper( string $helper ): void {
if ( ! $helper ) {
return;
}
Expand All @@ -1256,7 +1260,7 @@ private function print_helper( string $helper ) {
*
* @return void
*/
private function print_supplemental( string $supplemental ) {
private function print_supplemental( string $supplemental ): void {
if ( ! $supplemental ) {
return;
}
Expand Down
Loading

0 comments on commit 6cdf8f4

Please sign in to comment.