Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -20,5 +20,4 @@ defined('ABSPATH') || exit;
class Base extends \BerlinDB\Database\Base {
protected $prefix = 'wu';
} // end class Base;
}

View File

@ -20,5 +20,4 @@ defined('ABSPATH') || exit;
class Column extends \BerlinDB\Database\Column {
protected $prefix = 'wu';
} // end class Column;
}

View File

@ -17,4 +17,4 @@ defined('ABSPATH') || exit;
*
* @since 1.0.0
*/
class Compare extends \BerlinDB\Database\Compare {} // end class Compare;
class Compare extends \BerlinDB\Database\Compare {}

View File

@ -17,4 +17,4 @@ defined('ABSPATH') || exit;
*
* @since 1.0.0
*/
class Date extends \BerlinDB\Database\Date {} // end class Date;
class Date extends \BerlinDB\Database\Date {}

View File

@ -17,265 +17,242 @@ defined('ABSPATH') || exit;
*
* @since 2.0.0
*/
abstract class Enum
{
/**
* The default value.
*/
const __default = false;
abstract class Enum {
/**
* The default value.
*/
const __default = false;
// phpcs:ignore
/**
* The options available.
*
* @since 2.0.0
* @var array
*/
static $options = array();
/**
* @var string
*/
private $value = '';
/**
* Constructor method. Takes the value you want to set.
*
* @since 2.0.0
*
* @param string $value The value to be set.
*/
public function __construct($value = '')
{
$this->value = $value;
}
// end __construct;
// Needs to be Implemented
/**
* Returns an array with values => CSS Classes.
*
* @since 2.0.0
* @return array
*/
abstract protected function classes();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
abstract protected function labels();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
protected function icon_classes() {
* The options available.
*
* @since 2.0.0
* @var array
*/
static $options = array();
/**
* @var string
*/
private $value = '';
/**
* Constructor method. Takes the value you want to set.
*
* @since 2.0.0
*
* @param string $value The value to be set.
*/
public function __construct($value = '') {
$this->value = $value;
}
return array();
// Needs to be Implemented
/**
* Returns an array with values => CSS Classes.
*
* @since 2.0.0
* @return array
*/
abstract protected function classes();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
abstract protected function labels();
/**
* Returns an array with values => labels.
*
* @since 2.0.0
* @return void
*/
protected function icon_classes() {
}
// end icon_classes;
/**
* Returns the options available as constants.
*
* @since 2.0.0
* @return array
*/
public static function get_options() {
return array();
}
$hook = static::get_hook_name();
/**
* Returns the options available as constants.
*
* @since 2.0.0
* @return array
*/
public static function get_options() {
if (!isset(static::$options[$hook])) {
$hook = static::get_hook_name();
$reflector = new \ReflectionClass(static::class);
if ( ! isset(static::$options[ $hook ])) {
$reflector = new \ReflectionClass(static::class);
static::$options[$hook] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants());
static::$options[ $hook ] = apply_filters("wu_available_{$hook}_options", $reflector->getConstants());
}
} // end if;
return static::$options[ $hook ];
}
return static::$options[$hook];
public static function get_allowed_list($string = false) {
}
// end get_options;
public static function get_allowed_list($string = false) {
$options = array_unique(self::get_options());
$options = array_unique(self::get_options());
return $string ? implode(',', $options) : $options;
}
return $string ? implode(',', $options) : $options;
/**
* Returns the value loaded here.
*
* This runs through is_valid and returns the
* default value if a invalid value is passed on.
*
* @since 2.0.0
* @return string
*/
public function get_value() {
}
// end get_allowed_list;
/**
* Returns the value loaded here.
*
* This runs through is_valid and returns the
* default value if a invalid value is passed on.
*
* @since 2.0.0
* @return string
*/
public function get_value() {
if ($this->is_valid($this->value)) {
return $this->value;
}
if ($this->is_valid($this->value)) {
return static::__default;
}
return $this->value;
/**
* Check for the the validity of the value passed.
*
* @since 2.0.0
*
* @param string $value The string.
* @return boolean
*/
public function is_valid($value) {
} // end if;
$options = static::get_options();
return static::__default;
return in_array($value, $options, true);
}
}
// end get_value;
/**
* Check for the the validity of the value passed.
*
* @since 2.0.0
*
* @param string $value The string.
* @return boolean
*/
public function is_valid($value) {
/**
* Returns the label of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_label() {
$options = static::get_options();
$hook = static::get_hook_name();
return in_array($value, $options, true);
$labels = apply_filters("wu_available_{$hook}_labels", $this->labels());
}
// end is_valid;
/**
* Returns the label of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_label() {
return $this->exists_or_default($labels, $this->get_value());
}
$hook = static::get_hook_name();
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_classes() {
$labels = apply_filters("wu_available_{$hook}_labels", $this->labels());
$hook = static::get_hook_name();
return $this->exists_or_default($labels, $this->get_value());
$classes = apply_filters("wu_available_{$hook}_classes", $this->classes());
}
// end get_label;
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_classes() {
return $this->exists_or_default($classes, $this->get_value());
}
$hook = static::get_hook_name();
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_icon_classes() {
$classes = apply_filters("wu_available_{$hook}_classes", $this->classes());
$hook = static::get_hook_name();
return $this->exists_or_default($classes, $this->get_value());
$classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes());
}
// end get_classes;
/**
* Returns the classes of a given value.
*
* @since 2.0.0
* @return string
*/
public function get_icon_classes() {
return $this->exists_or_default($classes, $this->get_value());
}
$hook = static::get_hook_name();
/**
* Returns an array of options.
*
* @since 2.0.0
* @return void
*/
public static function to_array() {
$classes = apply_filters("wu_available_{$hook}_icon_classes", $this->icon_classes());
static $instance;
return $this->exists_or_default($classes, $this->get_value());
if ($instance === null) {
$instance = new static();
}
}
// end get_icon_classes;
/**
* Returns an array of options.
*
* @since 2.0.0
* @return void
*/
public static function to_array() {
$hook = $instance::get_hook_name();
static $instance;
$labels = apply_filters("wu_{$hook}_to_array", $instance->labels());
if ($instance === null) {
return $labels;
}
$instance = new static;
/**
* Get the hook name for this class, so we can add filters.
*
* @since 2.0.0
* @return string
*/
public static function get_hook_name() {
} // end if;
$class_name = (new \ReflectionClass(static::class))->getShortName();
$hook = $instance::get_hook_name();
return strtolower($class_name);
}
$labels = apply_filters("wu_{$hook}_to_array", $instance->labels());
/**
* Checks if a key exists on an array, otherwise returns a default value.
*
* @since 2.0.0
*
* @param array $array The array to check.
* @param string $key The key to check.
* @param string $default The default value.
* @return string
*/
public function exists_or_default($array, $key, $default = '') {
return $labels;
if (empty($default)) {
$default = isset($array[ static::__default ]) ? $array[ static::__default ] : '';
}
}
// end to_array;
/**
* Get the hook name for this class, so we can add filters.
*
* @since 2.0.0
* @return string
*/
public static function get_hook_name() {
return isset($array[ $key ]) ? $array[ $key ] : $default;
}
$class_name = (new \ReflectionClass(static::class))->getShortName();
/**
* Converts this to string.
*
* @since 2.0.0
* @return string
*/
public function __toString(): string {
return strtolower($class_name);
return $this->get_value();
}
}
// end get_hook_name;
/**
* Checks if a key exists on an array, otherwise returns a default value.
*
* @since 2.0.0
*
* @param array $array The array to check.
* @param string $key The key to check.
* @param string $default The default value.
* @return string
*/
public function exists_or_default($array, $key, $default = '') {
/**
* Magic method to allow for constants to be called.
*
* @since 2.0.0
*
* @param string $name The name of the constants.
* @param array $arguments The list of arguments. Not really needed here.
* @return string
*/
public static function __callStatic($name, $arguments) {
if (empty($default)) {
$class_name = static::class;
$default = isset($array[static::__default]) ? $array[static::__default] : '';
} // end if;
return isset($array[$key]) ? $array[$key] : $default;
}
// end exists_or_default;
/**
* Converts this to string.
*
* @since 2.0.0
* @return string
*/
public function __toString(): string {
return $this->get_value();
}
// end __toString;
/**
* Magic method to allow for constants to be called.
*
* @since 2.0.0
*
* @param string $name The name of the constants.
* @param array $arguments The list of arguments. Not really needed here.
* @return string
*/
public static function __callStatic($name, $arguments) {
$class_name = static::class;
return constant("$class_name::$name");
}
// end __callStatic;
} // end class Enum;
return constant("$class_name::$name");
}
}

View File

@ -17,4 +17,4 @@ defined('ABSPATH') || exit;
*
* @since 1.0.0
*/
class Meta extends \BerlinDB\Database\Meta {} // end class Meta;
class Meta extends \BerlinDB\Database\Meta {}

View File

@ -19,7 +19,7 @@ defined('ABSPATH') || exit;
*/
class Query extends \BerlinDB\Database\Query {
/**
/**
* The prefix for the custom table.
*
* @since 2.0.0
@ -73,17 +73,14 @@ class Query extends \BerlinDB\Database\Query {
$cache_group = $this->apply_prefix($this->cache_group, '-');
if ($this->global_cache && !in_array($cache_group, self::$added_globals, true)) {
if ($this->global_cache && ! in_array($cache_group, self::$added_globals, true)) {
wp_cache_add_global_groups(array($cache_group));
self::$added_globals[] = $cache_group;
} // end if;
}
parent::__construct($query);
} // end __construct;
}
/**
* Get the plural name.
@ -94,7 +91,5 @@ class Query extends \BerlinDB\Database\Query {
public function get_plural_name() {
return $this->item_name_plural;
} // end get_plural_name;
} // end class Query;
}
}

View File

@ -20,5 +20,4 @@ defined('ABSPATH') || exit;
class Row extends \BerlinDB\Database\Row {
protected $prefix = 'wu';
} // end class Row;
}

View File

@ -20,5 +20,4 @@ defined('ABSPATH') || exit;
class Schema extends \BerlinDB\Database\Schema {
protected $prefix = 'wu';
} // end class Schema;
}

View File

@ -47,21 +47,16 @@ abstract class Table extends \BerlinDB\Database\Table {
*/
public function is_upgradeable() {
if (!is_main_network()) {
if ( ! is_main_network()) {
return false;
}
} // end if;
if (!is_main_site()) {
if ( ! is_main_site()) {
return false;
} // end if;
}
return true;
} // end is_upgradeable;
}
/**
* Adds a caching layer to the parent exists method.
@ -72,13 +67,9 @@ abstract class Table extends \BerlinDB\Database\Table {
public function exists() {
if ($this->_exists === null) {
$this->_exists = parent::exists();
} // end if;
}
return $this->_exists;
} // end exists;
} // end class Table;
}
}