refactor: remove Hungarian notation

FINALLY close #34
This commit is contained in:
Ben Goldsworthy 2021-05-02 20:46:44 +01:00
parent 7c0b05b59e
commit 205764f91a
13 changed files with 1637 additions and 1637 deletions

View file

@ -55,7 +55,7 @@ class Config {
*
* @var string
*/
const C_STR_PLUGIN_PUBLIC_NAME = '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>';
const PLUGIN_PUBLIC_NAME = '<span class="footnotes_logo footnotes_logo_part1">foot</span><span class="footnotes_logo footnotes_logo_part2">notes</span>';
/**
* Public plugin name for use as a dashboard heading.
@ -72,7 +72,7 @@ class Config {
*
* @var string
*/
const C_STR_PLUGIN_HEADING_NAME = '<span class="footnotes_logo_heading footnotes_logo_part1_heading">foot</span><span class="footnotes_logo_heading footnotes_logo_part2_heading">notes</span>';
const PLUGIN_HEADING_NAME = '<span class="footnotes_logo_heading footnotes_logo_part1_heading">foot</span><span class="footnotes_logo_heading footnotes_logo_part2_heading">notes</span>';
/**
* HTML element for the love symbol.
@ -83,7 +83,7 @@ class Config {
*
* @var string
*/
const C_STR_LOVE_SYMBOL = '<span style="color:#ff6d3b; font-weight:bold;">&hearts;</span>';
const LOVE_SYMBOL = '<span style="color:#ff6d3b; font-weight:bold;">&hearts;</span>';
/**
* HTML element for the love symbol used in dashboard heading
@ -94,7 +94,7 @@ class Config {
*
* @var string
*/
const C_STR_LOVE_SYMBOL_HEADING = '<span class="footnotes_heart_heading">&hearts;</span>';
const LOVE_SYMBOL_HEADING = '<span class="footnotes_heart_heading">&hearts;</span>';
/**
* Shortcode to NOT display the LOVE ME slug on certain pages.
@ -105,5 +105,5 @@ class Config {
*
* @var string
*/
const C_STR_NO_LOVE_SLUG = '[[no footnotes: love]]';
const NO_LOVE_SLUG = '[[no footnotes: love]]';
}

View file

@ -22,27 +22,27 @@ class Convert {
/**
* Converts an integer into the user-defined counter style for the footnotes.
*
* @param int $p_int_index Index to be converted.
* @param string $p_str_convert_style Counter style to use.
* @param int $index Index to be converted.
* @param string $convert_style Counter style to use.
* @return string The index converted to the defined counter style.
*
* @since 1.5.0
*/
public static function index( int $p_int_index, string $p_str_convert_style = 'arabic_plain' ): string {
switch ( $p_str_convert_style ) {
public static function index( int $index, string $convert_style = 'arabic_plain' ): string {
switch ( $convert_style ) {
case 'roman':
return self::to_roman( $p_int_index, true );
return self::to_roman( $index, true );
case 'roman_low':
return self::to_roman( $p_int_index, false );
return self::to_roman( $index, false );
case 'latin_high':
return self::to_latin( $p_int_index, true );
return self::to_latin( $index, true );
case 'latin_low':
return self::to_latin( $p_int_index, false );
return self::to_latin( $index, false );
case 'arabic_leading':
return self::to_arabic_leading( $p_int_index );
return self::to_arabic_leading( $index );
case 'arabic_plain':
default:
return (string) $p_int_index;
return (string) $index;
}
}
@ -52,63 +52,63 @@ class Convert {
* This function works from values AZZ (meaning there is a limit of 676
* gootnotes per Page).
*
* @param int $p_int_value Value to be converted.
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
* @todo Replace with built-in char casting.
*/
private static function to_latin( int $p_int_value, bool $p_bool_upper_case ): string {
private static function to_latin( int $value, bool $upper_case ): string {
// Output string.
$l_str_return = '';
$l_int_offset = 0;
$return = '';
$offset = 0;
// Check if the value is higher then 26 = Z.
while ( $p_int_value > 26 ) {
while ( $value > 26 ) {
// Increase offset and reduce counter.
$l_int_offset++;
$p_int_value -= 26;
$offset++;
$value -= 26;
}
// If offset set (more then Z), then add a new letter in front.
if ( $l_int_offset > 0 ) {
$l_str_return = chr( $l_int_offset + 64 );
if ( $offset > 0 ) {
$return = chr( $offset + 64 );
}
// Add the origin letter.
$l_str_return .= chr( $p_int_value + 64 );
$return .= chr( $value + 64 );
// Return the latin character representing the integer.
if ( $p_bool_upper_case ) {
return strtoupper( $l_str_return );
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $l_str_return );
return strtolower( $return );
}
/**
* Converts an integer to a leading-0 integer.
*
* @param int $p_int_value Value to be converted.
* @param int $value Value to be converted.
* @return string Value with a leading zero.
*
* @since 1.0-gamma
* @todo Replace with built-in string formatting.
*/
private static function to_arabic_leading( int $p_int_value ): string {
private static function to_arabic_leading( int $value ): string {
// Add a leading 0 if number lower then 10.
if ( $p_int_value < 10 ) {
return '0' . $p_int_value;
if ( $value < 10 ) {
return '0' . $value;
}
return $p_int_value;
return $value;
}
/**
* Converts an integer to a Roman numeral.
*
* @param int $p_int_value Value to be converted.
* @param bool $p_bool_upper_case Whether to convert the value to upper-case.
* @param int $value Value to be converted.
* @param bool $upper_case Whether to convert the value to upper-case.
*
* @since 1.0-gamma
*/
private static function to_roman( int $p_int_value, bool $p_bool_upper_case ): string {
private static function to_roman( int $value, bool $upper_case ): string {
// Table containing all necessary roman letters.
$l_arr_roman_numerals = array(
$roman_numerals = array(
'M' => 1000,
'CM' => 900,
'D' => 500,
@ -124,38 +124,38 @@ class Convert {
'I' => 1,
);
// Return value.
$l_str_return = '';
$return = '';
// Iterate through integer value until it is reduced to 0.
while ( $p_int_value > 0 ) {
foreach ( $l_arr_roman_numerals as $l_str_roman => $l_int_arabic ) {
if ( $p_int_value >= $l_int_arabic ) {
$p_int_value -= $l_int_arabic;
$l_str_return .= $l_str_roman;
while ( $value > 0 ) {
foreach ( $roman_numerals as $roman => $arabic ) {
if ( $value >= $arabic ) {
$value -= $arabic;
$return .= $roman;
break;
}
}
}
// Return roman letters as string.
if ( $p_bool_upper_case ) {
return strtoupper( $l_str_return );
if ( $upper_case ) {
return strtoupper( $return );
}
return strtolower( $l_str_return );
return strtolower( $return );
}
/**
* Converts a string depending on its value to a boolean.
*
* @param string $p_str_value String to be converted to boolean.
* @param string $value String to be converted to boolean.
* @return bool Boolean value represented by the string.
*
* @since 1.0-beta
* @todo Replace with built-in type casting.
*/
public static function to_bool( string $p_str_value ): bool {
public static function to_bool( string $value ): bool {
// Convert string to lower-case to make it easier.
$p_str_value = strtolower( $p_str_value );
$value = strtolower( $value );
// Check if string seems to contain a "true" value.
switch ( $p_str_value ) {
switch ( $value ) {
case 'checked':
case 'yes':
case 'true':
@ -170,29 +170,29 @@ class Convert {
/**
* Get an HTML array short code depending on Arrow-Array key index.
*
* @param int $p_int_index Index representing the arrow. If empty, all arrows are specified.
* @param int $index Index representing the arrow. If empty, all arrows are specified.
* @return string|string[] Array of all arrows if index is empty, otherwise HTML tag of a specific arrow.
*
* @since 1.3.2
* @todo Review.
* @todo Single return type.
*/
public static function get_arrow( int $p_int_index = -1 ): string|array {
public static function get_arrow( int $index = -1 ): string|array {
// Define all possible arrows.
$l_arr_arrows = array( '&#8593;', '&#8613;', '&#8607;', '&#8617;', '&#8626;', '&#8629;', '&#8657;', '&#8673;', '&#8679;', '&#65514;' );
$arrows = array( '&#8593;', '&#8613;', '&#8607;', '&#8617;', '&#8626;', '&#8629;', '&#8657;', '&#8673;', '&#8679;', '&#65514;' );
// Convert index to an integer.
if ( ! is_int( $p_int_index ) ) {
$p_int_index = (int) $p_int_index;
if ( ! is_int( $index ) ) {
$index = (int) $index;
}
// Return the whole arrow array.
if ( $p_int_index < 0 ) {
return $l_arr_arrows;
if ( $index < 0 ) {
return $arrows;
}
if ( $p_int_index > count( $l_arr_arrows ) ) {
return $l_arr_arrows;
if ( $index > count( $arrows ) ) {
return $arrows;
}
// Return a single arrow.
return $l_arr_arrows[ $p_int_index ];
return $arrows[ $index ];
}
// phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_var_dump, WordPress.PHP.DevelopmentFunctions.error_log_print_r

View file

@ -32,7 +32,7 @@ class i18n {
* Load the plugin text domain for translation.
*
* @since 1.5.1
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$p_str_language_code` parameter.
* @since 2.8.0 Rename from `load()` to `load_plugin_textdomain()`. Remove unused `$language_code` parameter.
*
* @return void
*/

File diff suppressed because it is too large Load diff

View file

@ -36,7 +36,7 @@ class Template {
*
* @var string
*/
const C_STR_DASHBOARD = 'admin/partials';
const DASHBOARD = 'admin/partials';
/**
* Directory name for public partials.
@ -45,21 +45,21 @@ class Template {
*
* @var string
*/
const C_STR_PUBLIC = 'public/partials';
const PUBLIC = 'public/partials';
/**
* Contains the content of the template after initialize.
*
* @since 1.5.0
*/
private ?string $a_str_original_content = '';
private ?string $original_content = '';
/**
* Contains the content of the template after initialize with replaced place holders.
*
* @since 1.5.0
*/
private string $a_str_replaced_content = '';
private string $replaced_content = '';
/**
* Plugin Directory
@ -74,22 +74,22 @@ class Template {
* @since 1.5.0
* @todo Refactor templating.
*
* @param string $p_str_file_type Template file type.
* @param string $p_str_file_name Template file name inside the `partials/` directory, without the file extension.
* @param string $p_str_extension (optional) Template file extension (default: 'html').
* @param string $file_type Template file type.
* @param string $file_name Template file name inside the `partials/` directory, without the file extension.
* @param string $extension (optional) Template file extension (default: 'html').
* @return void
*/
public function __construct( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ) {
public function __construct( string $file_type, string $file_name, string $extension = 'html' ) {
// No template file type and/or file name set.
if ( empty( $p_str_file_type ) ) {
if ( empty( $file_type ) ) {
return;
}
if ( empty( $p_str_file_name ) ) {
if ( empty( $file_name ) ) {
return;
}
$this->plugin_directory = plugin_dir_path( __DIR__ );
$template = $this->get_template( $p_str_file_type, $p_str_file_name, $p_str_extension );
$template = $this->get_template( $file_type, $file_name, $extension );
if ( $template ) {
$this->process_template( $template );
} else {
@ -104,21 +104,21 @@ class Template {
* @since 1.5.0
* @todo Refactor templating.
*
* @param string[] $p_arr_placeholders Placeholders (key = placeholder, value = value).
* @param string[] $placeholders Placeholders (key = placeholder, value = value).
* @return bool `true` on Success, `false` if placeholders invalid.
*/
public function replace( array $p_arr_placeholders ): bool {
public function replace( array $placeholders ): bool {
// No placeholders set.
if ( empty( $p_arr_placeholders ) ) {
if ( empty( $placeholders ) ) {
return false;
}
// Template content is empty.
if ( empty( $this->a_str_replaced_content ) ) {
if ( empty( $this->replaced_content ) ) {
return false;
}
// Iterate through each placeholder and replace it with its value.
foreach ( $p_arr_placeholders as $l_str_placeholder => $l_str_value ) {
$this->a_str_replaced_content = str_replace( '[[' . $l_str_placeholder . ']]', (string) $l_str_value, $this->a_str_replaced_content );
foreach ( $placeholders as $placeholder => $value ) {
$this->replaced_content = str_replace( '[[' . $placeholder . ']]', (string) $value, $this->replaced_content );
}
// Success.
return true;
@ -133,7 +133,7 @@ class Template {
* @return void
*/
public function reload() {
$this->a_str_replaced_content = $this->a_str_original_content;
$this->replaced_content = $this->original_content;
}
/**
@ -145,7 +145,7 @@ class Template {
* @return string Template content with replaced placeholders.
*/
public function get_content(): string {
return $this->a_str_replaced_content;
return $this->replaced_content;
}
/**
@ -159,14 +159,14 @@ class Template {
*/
public function process_template( string $template ) {
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$this->a_str_original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
$this->original_content = preg_replace( '#<!--.+?-->#s', '', file_get_contents( $template ) );
// phpcs:enable
$this->a_str_original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->a_str_original_content );
$this->a_str_original_content = str_replace( "\n", '', $this->a_str_original_content );
$this->a_str_original_content = str_replace( "\r", '', $this->a_str_original_content );
$this->a_str_original_content = str_replace( "\t", ' ', $this->a_str_original_content );
$this->a_str_original_content = preg_replace( '# +#', ' ', $this->a_str_original_content );
$this->a_str_original_content = str_replace( ' >', '>', $this->a_str_original_content );
$this->original_content = preg_replace( '#/\*\*.+?\*/#s', '', $this->original_content );
$this->original_content = str_replace( "\n", '', $this->original_content );
$this->original_content = str_replace( "\r", '', $this->original_content );
$this->original_content = str_replace( "\t", ' ', $this->original_content );
$this->original_content = preg_replace( '# +#', ' ', $this->original_content );
$this->original_content = str_replace( ' >', '>', $this->original_content );
$this->reload();
}
@ -177,12 +177,12 @@ class Template {
* @todo Refactor templating.
* @todo Single return type.
*
* @param string $p_str_file_type The file type of the template.
* @param string $p_str_file_name The file name of the template.
* @param string $p_str_extension The file extension of the template.
* @param string $file_type The file type of the template.
* @param string $file_name The file name of the template.
* @param string $extension The file extension of the template.
* @return string|bool `false` or the template path
*/
public function get_template( string $p_str_file_type, string $p_str_file_name, string $p_str_extension = 'html' ): string|bool {
public function get_template( string $file_type, string $file_name, string $extension = 'html' ): string|bool {
$located = false;
/*
@ -195,7 +195,7 @@ class Template {
*/
$template_directory = apply_filters( '', 'footnotes/' );
$custom_directory = apply_filters( 'custom_template_directory', 'footnotes-custom/' );
$template_name = $p_str_file_type . '/' . $p_str_file_name . '.' . $p_str_extension;
$template_name = $file_type . '/' . $file_name . '.' . $extension;
// Look in active theme.
if ( file_exists( trailingslashit( get_stylesheet_directory() ) . $template_directory . $template_name ) ) {