refactor: run Rector ORDER
setlist
This commit is contained in:
parent
667d8dada9
commit
114121a7e2
9 changed files with 542 additions and 568 deletions
|
@ -46,102 +46,6 @@ class Convert {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer into Latin ASCII characters, either lower or upper-case.
|
||||
*
|
||||
* This function works from values A–ZZ (meaning there is a limit of 676
|
||||
* gootnotes per Page).
|
||||
*
|
||||
* @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 $value, bool $upper_case ): string {
|
||||
// Output string.
|
||||
$return = '';
|
||||
$offset = 0;
|
||||
// Check if the value is higher then 26 = Z.
|
||||
while ( $value > 26 ) {
|
||||
// Increase offset and reduce counter.
|
||||
$offset++;
|
||||
$value -= 26;
|
||||
}
|
||||
// If offset set (more then Z), then add a new letter in front.
|
||||
if ( $offset > 0 ) {
|
||||
$return = chr( $offset + 64 );
|
||||
}
|
||||
// Add the origin letter.
|
||||
$return .= chr( $value + 64 );
|
||||
// Return the latin character representing the integer.
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a leading-0 integer.
|
||||
*
|
||||
* @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 $value ): string {
|
||||
// Add a leading 0 if number lower then 10.
|
||||
if ( $value < 10 ) {
|
||||
return '0' . $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an integer to a Roman numeral.
|
||||
*
|
||||
* @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 $value, bool $upper_case ): string {
|
||||
// Table containing all necessary roman letters.
|
||||
$roman_numerals = array(
|
||||
'M' => 1000,
|
||||
'CM' => 900,
|
||||
'D' => 500,
|
||||
'CD' => 400,
|
||||
'C' => 100,
|
||||
'XC' => 90,
|
||||
'L' => 50,
|
||||
'XL' => 40,
|
||||
'X' => 10,
|
||||
'IX' => 9,
|
||||
'V' => 5,
|
||||
'IV' => 4,
|
||||
'I' => 1,
|
||||
);
|
||||
// Return value.
|
||||
$return = '';
|
||||
// Iterate through integer value until it is reduced to 0.
|
||||
while ( $value > 0 ) {
|
||||
foreach ( $roman_numerals as $roman => $arabic ) {
|
||||
if ( $value >= $arabic ) {
|
||||
$value -= $arabic;
|
||||
$return .= $roman;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return roman letters as string.
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $return );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string depending on its value to a boolean.
|
||||
*
|
||||
|
@ -230,5 +134,98 @@ class Convert {
|
|||
}
|
||||
echo '<br/>';
|
||||
}
|
||||
/**
|
||||
* Converts an integer into Latin ASCII characters, either lower or upper-case.
|
||||
*
|
||||
* This function works from values A–ZZ (meaning there is a limit of 676
|
||||
* gootnotes per Page).
|
||||
*
|
||||
* @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 $value, bool $upper_case ): string {
|
||||
// Output string.
|
||||
$return = '';
|
||||
$offset = 0;
|
||||
// Check if the value is higher then 26 = Z.
|
||||
while ( $value > 26 ) {
|
||||
// Increase offset and reduce counter.
|
||||
$offset++;
|
||||
$value -= 26;
|
||||
}
|
||||
// If offset set (more then Z), then add a new letter in front.
|
||||
if ( $offset > 0 ) {
|
||||
$return = chr( $offset + 64 );
|
||||
}
|
||||
// Add the origin letter.
|
||||
$return .= chr( $value + 64 );
|
||||
// Return the latin character representing the integer.
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $return );
|
||||
}
|
||||
/**
|
||||
* Converts an integer to a leading-0 integer.
|
||||
*
|
||||
* @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 $value ): string {
|
||||
// Add a leading 0 if number lower then 10.
|
||||
if ( $value < 10 ) {
|
||||
return '0' . $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
/**
|
||||
* Converts an integer to a Roman numeral.
|
||||
*
|
||||
* @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 $value, bool $upper_case ): string {
|
||||
// Table containing all necessary roman letters.
|
||||
$roman_numerals = array(
|
||||
'M' => 1000,
|
||||
'CM' => 900,
|
||||
'D' => 500,
|
||||
'CD' => 400,
|
||||
'C' => 100,
|
||||
'XC' => 90,
|
||||
'L' => 50,
|
||||
'XL' => 40,
|
||||
'X' => 10,
|
||||
'IX' => 9,
|
||||
'V' => 5,
|
||||
'IV' => 4,
|
||||
'I' => 1,
|
||||
);
|
||||
// Return value.
|
||||
$return = '';
|
||||
// Iterate through integer value until it is reduced to 0.
|
||||
while ( $value > 0 ) {
|
||||
foreach ( $roman_numerals as $roman => $arabic ) {
|
||||
if ( $value >= $arabic ) {
|
||||
$value -= $arabic;
|
||||
$return .= $roman;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Return roman letters as string.
|
||||
if ( $upper_case ) {
|
||||
return strtoupper( $return );
|
||||
}
|
||||
return strtolower( $return );
|
||||
}
|
||||
// phpcs:enable WordPress.PHP.DevelopmentFunctions.error_log_var_dump, WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
||||
}
|
||||
|
|
|
@ -97,6 +97,44 @@ class Core {
|
|||
$this->define_public_hooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the loader to execute all of the hooks with WordPress.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the plugin used to uniquely identify it within the
|
||||
* context of WordPress and to define internationalization functionality.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_plugin_name(): string {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the class that orchestrates the hooks with the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_loader(): Loader {
|
||||
return $this->loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version number of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_version(): string {
|
||||
return $this->version;
|
||||
}
|
||||
/**
|
||||
* Load the required dependencies for this plugin.
|
||||
*
|
||||
|
@ -154,7 +192,6 @@ class Core {
|
|||
$this->loader = new Loader();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the locale for this plugin for internationalization.
|
||||
*
|
||||
|
@ -173,7 +210,6 @@ class Core {
|
|||
$this->loader->add_action( 'plugins_loaded', $i18n, 'load_plugin_textdomain' );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the admin area functionality of the
|
||||
* plugin.
|
||||
|
@ -205,7 +241,6 @@ class Core {
|
|||
$this->loader->add_action( 'wp_ajax_footnotes_getTags', $admin->wysiwyg, 'ajax_callback' );
|
||||
// phpcs:enable
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all of the hooks related to the public-facing functionality of
|
||||
* the plugin.
|
||||
|
@ -224,43 +259,4 @@ class Core {
|
|||
|
||||
$this->loader->add_action( 'widgets_init', $general, 'register_widgets' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the loader to execute all of the hooks with WordPress.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
$this->loader->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the plugin used to uniquely identify it within the
|
||||
* context of WordPress and to define internationalization functionality.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_plugin_name(): string {
|
||||
return $this->plugin_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the class that orchestrates the hooks with the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_loader(): Loader {
|
||||
return $this->loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version number of the plugin.
|
||||
*
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public function get_version(): string {
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,6 +91,25 @@ class Loader {
|
|||
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the filters and actions with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
foreach ( $this->filters as $filter ) {
|
||||
add_filter( $filter['hook'], array( $filter['component'], $filter['callback'] ), $filter['priority'], $filter['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $action ) {
|
||||
add_action( $action['hook'], array( $action['component'], $action['callback'] ), $action['priority'], $action['accepted_args'] );
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* A utility function that is used to register the actions and hooks into a single
|
||||
* collection.
|
||||
|
@ -127,24 +146,4 @@ class Loader {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the filters and actions with WordPress.
|
||||
*
|
||||
* @since 2.8.0
|
||||
* @see Loader::add() For more information on the hook array format.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
foreach ( $this->filters as $filter ) {
|
||||
add_filter( $filter['hook'], array( $filter['component'], $filter['callback'] ), $filter['priority'], $filter['accepted_args'] );
|
||||
}
|
||||
|
||||
foreach ( $this->actions as $action ) {
|
||||
add_action( $action['hook'], array( $action['component'], $action['callback'] ), $action['priority'], $action['accepted_args'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1103,16 +1103,6 @@ class Settings {
|
|||
*/
|
||||
const FOOTNOTE_SECTION_SHORTCODE = 'footnotes_inputfield_section_shortcode';
|
||||
|
||||
/**********************************************************************
|
||||
* SETTINGS STORAGE.
|
||||
**********************************************************************/
|
||||
/**
|
||||
* Stores a singleton reference of this class.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private static ?\footnotes\includes\Settings $instance = null;
|
||||
|
||||
/**
|
||||
* Contains all Settings Container names.
|
||||
*
|
||||
|
@ -1330,6 +1320,15 @@ class Settings {
|
|||
* @todo Create `PreferencesSet` class.
|
||||
*/
|
||||
private array $settings = array();
|
||||
/**********************************************************************
|
||||
* SETTINGS STORAGE.
|
||||
**********************************************************************/
|
||||
/**
|
||||
* Stores a singleton reference of this class.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private static ?\footnotes\includes\Settings $instance = null;
|
||||
|
||||
/**
|
||||
* Loads all Settings from each WordPress Settings Container.
|
||||
|
@ -1340,21 +1339,6 @@ class Settings {
|
|||
$this->load_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a singleton of this class.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Remove?
|
||||
*/
|
||||
public static function instance(): self {
|
||||
// No instance defined yet, load it.
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
// Return a singleton of this class.
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of a specified Settings Container.
|
||||
*
|
||||
|
@ -1379,51 +1363,6 @@ class Settings {
|
|||
return $this->default[ $this->container[ $index ] ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all Settings from each Settings container.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function load_all(): void {
|
||||
// Clear current settings.
|
||||
$this->settings = array();
|
||||
$num_settings = count( $this->container );
|
||||
for ( $i = 0; $i < $num_settings; $i++ ) {
|
||||
// Load settings.
|
||||
$this->settings = array_merge( $this->settings, $this->load( $i ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all settings from specified Settings Containers.
|
||||
*
|
||||
* @param int $index Settings container index.
|
||||
* @return (string|int)[] Loaded settings (or defaults if specified container is empty).
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function load( int $index ): array {
|
||||
// Load all settings from container.
|
||||
$options = get_option( $this->get_container( $index ) );
|
||||
// Load all default settings.
|
||||
$default = $this->default[ $this->get_container( $index ) ];
|
||||
|
||||
// No settings found, set them to their default value.
|
||||
if ( empty( $options ) ) {
|
||||
return $default;
|
||||
}
|
||||
// Iterate through all available settings ( = default values).
|
||||
foreach ( $default as $key => $value ) {
|
||||
// Available setting not found in the container.
|
||||
if ( ! array_key_exists( $key, $options ) ) {
|
||||
// Define the setting with its default value.
|
||||
$options[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
// Return settings loaded from Container.
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a whole Setting Container on save.
|
||||
*
|
||||
|
@ -1467,4 +1406,61 @@ class Settings {
|
|||
register_setting( $this->get_container( $i ), $this->get_container( $i ) );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns a singleton of this class.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @todo Remove?
|
||||
*/
|
||||
public static function instance(): self {
|
||||
// No instance defined yet, load it.
|
||||
if ( ! self::$instance ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
// Return a singleton of this class.
|
||||
return self::$instance;
|
||||
}
|
||||
/**
|
||||
* Loads all Settings from each Settings container.
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function load_all(): void {
|
||||
// Clear current settings.
|
||||
$this->settings = array();
|
||||
$num_settings = count( $this->container );
|
||||
for ( $i = 0; $i < $num_settings; $i++ ) {
|
||||
// Load settings.
|
||||
$this->settings = array_merge( $this->settings, $this->load( $i ) );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Loads all settings from specified Settings Containers.
|
||||
*
|
||||
* @param int $index Settings container index.
|
||||
* @return (string|int)[] Loaded settings (or defaults if specified container is empty).
|
||||
*
|
||||
* @since 1.5.0
|
||||
*/
|
||||
private function load( int $index ): array {
|
||||
// Load all settings from container.
|
||||
$options = get_option( $this->get_container( $index ) );
|
||||
// Load all default settings.
|
||||
$default = $this->default[ $this->get_container( $index ) ];
|
||||
|
||||
// No settings found, set them to their default value.
|
||||
if ( empty( $options ) ) {
|
||||
return $default;
|
||||
}
|
||||
// Iterate through all available settings ( = default values).
|
||||
foreach ( $default as $key => $value ) {
|
||||
// Available setting not found in the container.
|
||||
if ( ! array_key_exists( $key, $options ) ) {
|
||||
// Define the setting with its default value.
|
||||
$options[ $key ] = $value;
|
||||
}
|
||||
}
|
||||
// Return settings loaded from Container.
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,12 @@ class Template {
|
|||
* @var string
|
||||
*/
|
||||
const PUBLIC = 'public/partials';
|
||||
/**
|
||||
* Plugin Directory
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*/
|
||||
public string $plugin_directory;
|
||||
|
||||
/**
|
||||
* Contains the content of the template after initialize.
|
||||
|
@ -61,13 +67,6 @@ class Template {
|
|||
*/
|
||||
private string $replaced_content = '';
|
||||
|
||||
/**
|
||||
* Plugin Directory
|
||||
*
|
||||
* @since 2.4.0d3
|
||||
*/
|
||||
public string $plugin_directory;
|
||||
|
||||
/**
|
||||
* Class Constructor. Reads and loads the template file without replace any placeholder.
|
||||
*
|
||||
|
|
Reference in a new issue