This commit is contained in:
Javier Casares 2026-03-28 15:38:41 +00:00
commit 92d56fe84d
4445 changed files with 992 additions and 529601 deletions

View file

@ -16,9 +16,9 @@ if ( ! defined( 'ABSPATH' ) ) {
* @since 1.0.0
*
* @param string $token Plain token.
* @return string Encrypted token.
* @return string Encrypted token, or empty string on failure.
*/
function robotstxt_docmd_encrypt_token( $token ) {
function robotstxt_docmd_encrypt_token( string $token ): string {
if ( empty( $token ) ) {
return '';
}
@ -27,9 +27,12 @@ function robotstxt_docmd_encrypt_token( $token ) {
$key = wp_salt( 'auth' );
$iv_length = openssl_cipher_iv_length( 'aes-256-cbc' );
$iv = openssl_random_pseudo_bytes( $iv_length );
$encrypted = openssl_encrypt( $token, 'aes-256-cbc', $key, 0, $iv );
if ( false === $encrypted ) {
return '';
}
return base64_encode( $iv . $encrypted ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
}
@ -39,9 +42,9 @@ function robotstxt_docmd_encrypt_token( $token ) {
* @since 1.0.0
*
* @param string $encrypted_token Encrypted token.
* @return string Plain token.
* @return string Plain token, or empty string on failure.
*/
function robotstxt_docmd_decrypt_token( $encrypted_token ) {
function robotstxt_docmd_decrypt_token( string $encrypted_token ): string {
if ( empty( $encrypted_token ) ) {
return '';
}
@ -53,7 +56,8 @@ function robotstxt_docmd_decrypt_token( $encrypted_token ) {
$iv = substr( $decoded, 0, $iv_length );
$encrypted = substr( $decoded, $iv_length );
return openssl_decrypt( $encrypted, 'aes-256-cbc', $key, 0, $iv );
$decrypted = openssl_decrypt( $encrypted, 'aes-256-cbc', $key, 0, $iv );
return false !== $decrypted ? $decrypted : '';
}
/**
@ -66,10 +70,11 @@ function robotstxt_docmd_decrypt_token( $encrypted_token ) {
* @param string $file_path File path.
* @return string Generated title.
*/
function robotstxt_docmd_generate_title_from_path( $file_path ) {
function robotstxt_docmd_generate_title_from_path( string $file_path ): string {
// Get filename without extension.
$filename = basename( $file_path );
$title = preg_replace( '/\.(md|markdown)$/i', '', $filename );
$title = is_string( $title ) ? $title : $filename;
// Replace separators with spaces.
$title = str_replace( array( '-', '_' ), ' ', $title );
@ -91,7 +96,8 @@ function robotstxt_docmd_generate_title_from_path( $file_path ) {
);
foreach ( $abbreviations as $search => $replace ) {
$title = preg_replace( '/\b' . $search . '\b/', $replace, $title );
$result = preg_replace( '/\b' . $search . '\b/', $replace, $title );
$title = is_string( $result ) ? $result : $title;
}
return $title;
@ -105,7 +111,7 @@ function robotstxt_docmd_generate_title_from_path( $file_path ) {
* @param string $status Status (never, pending, success, error).
* @return string Badge HTML.
*/
function robotstxt_docmd_get_status_badge( $status ) {
function robotstxt_docmd_get_status_badge( string $status ): string {
$badges = array(
'never' => array(
'class' => 'status-never',
@ -133,3 +139,41 @@ function robotstxt_docmd_get_status_badge( $status ) {
esc_html( $badge['label'] )
);
}
/**
* Safely get a string value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array<string, mixed> $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param string $fallback Default value if key not found or not a string.
* @return string
*/
function robotstxt_docmd_input_string( array $input, string $key, string $fallback = '' ): string {
if ( isset( $input[ $key ] ) && is_string( $input[ $key ] ) ) {
return $input[ $key ];
}
return $fallback;
}
/**
* Safely get an integer value from a superglobal array
*
* Provides PHPStan level 9 compliant type-narrowing for superglobal access.
*
* @since 1.0.1
*
* @param array<string, mixed> $input The superglobal array ($_POST, $_GET, etc.).
* @param string $key The key to look for.
* @param int $fallback Default value if key not found or not numeric.
* @return int
*/
function robotstxt_docmd_input_int( array $input, string $key, int $fallback = 0 ): int {
if ( isset( $input[ $key ] ) && is_numeric( $input[ $key ] ) ) {
return (int) $input[ $key ];
}
return $fallback;
}