Skip to content

Commit 2e05531

Browse files
Copilotswissspidy
andcommitted
Refactor: extract TinyMCE version formatting and improve PHPDoc
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 0d519df commit 2e05531

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/Core_Command.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,6 @@ public function version( $args = [], $assoc_args = [] ) {
970970
return;
971971
}
972972

973-
$match = [];
974-
$found_version = preg_match( '/(\d)(\d+)-/', $details['tinymce_version'], $match );
975-
$human_readable_tiny_mce = $found_version ? "{$match[1]}.{$match[2]}" : '';
976-
977973
echo Utils\mustache_render(
978974
self::get_template_path( 'versions.mustache' ),
979975
[
@@ -982,9 +978,7 @@ public function version( $args = [], $assoc_args = [] ) {
982978
'local-package' => empty( $details['wp_local_package'] )
983979
? 'en_US'
984980
: $details['wp_local_package'],
985-
'mce-version' => $human_readable_tiny_mce
986-
? "{$human_readable_tiny_mce} ({$details['tinymce_version']})"
987-
: $details['tinymce_version'],
981+
'mce-version' => self::format_tinymce_version( $details['tinymce_version'] ),
988982
]
989983
);
990984
}
@@ -998,18 +992,14 @@ public function version( $args = [], $assoc_args = [] ) {
998992
* @when after_wp_load
999993
*
1000994
* @param string[] $args Positional arguments. Unused.
1001-
* @param array{extra?: bool} $assoc_args Associative arguments.
995+
* @param array $assoc_args Associative arguments passed through from version command.
1002996
*/
1003997
public function version_db_actual( $args = [], $assoc_args = [] ) {
1004998
$details = self::get_wp_details();
1005999

10061000
// Get the actual database version from the options table
10071001
$actual_db_version = get_option( 'db_version' );
10081002

1009-
$match = [];
1010-
$found_version = preg_match( '/(\d)(\d+)-/', $details['tinymce_version'], $match );
1011-
$human_readable_tiny_mce = $found_version ? "{$match[1]}.{$match[2]}" : '';
1012-
10131003
echo Utils\mustache_render(
10141004
self::get_template_path( 'versions.mustache' ),
10151005
[
@@ -1018,13 +1008,29 @@ public function version_db_actual( $args = [], $assoc_args = [] ) {
10181008
'local-package' => empty( $details['wp_local_package'] )
10191009
? 'en_US'
10201010
: $details['wp_local_package'],
1021-
'mce-version' => $human_readable_tiny_mce
1022-
? "{$human_readable_tiny_mce} ({$details['tinymce_version']})"
1023-
: $details['tinymce_version'],
1011+
'mce-version' => self::format_tinymce_version( $details['tinymce_version'] ),
10241012
]
10251013
);
10261014
}
10271015

1016+
/**
1017+
* Formats the TinyMCE version for display.
1018+
*
1019+
* @param string $tinymce_version The TinyMCE version string.
1020+
* @return string Formatted TinyMCE version.
1021+
*/
1022+
private static function format_tinymce_version( $tinymce_version ) {
1023+
$match = [];
1024+
$found_version = preg_match( '/(\d)(\d+)-/', $tinymce_version, $match );
1025+
$human_readable_tiny_mce = $found_version ? "{$match[1]}.{$match[2]}" : '';
1026+
1027+
if ( $human_readable_tiny_mce ) {
1028+
return "{$human_readable_tiny_mce} ({$tinymce_version})";
1029+
}
1030+
1031+
return $tinymce_version;
1032+
}
1033+
10281034
/**
10291035
* Gets version information from `wp-includes/version.php`.
10301036
*

0 commit comments

Comments
 (0)