From 48afc16cfae5d72e569dcf954eef3f4b8dbdbfbc Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 2 Dec 2018 22:16:54 -0600 Subject: [PATCH] Cleanup: Rename 'rename column to' to 'rename column' --- common/database/classes/database_string.php | 1 + common/database/traits/database_rename_column.php | 113 +++++++++++++++++++++ .../database/traits/database_rename_column_to.php | 75 -------------- 3 files changed, 114 insertions(+), 75 deletions(-) create mode 100644 common/database/traits/database_rename_column.php delete mode 100644 common/database/traits/database_rename_column_to.php diff --git a/common/database/classes/database_string.php b/common/database/classes/database_string.php index adf7886..f61b9a8 100644 --- a/common/database/classes/database_string.php +++ b/common/database/classes/database_string.php @@ -69,6 +69,7 @@ class c_database_string { public const REFERENCES = 'references'; public const REFRESH_VERSION = 'refresh version'; public const RENAME_TO = 'rename to'; + public const RENAME_COLUMN = 'rename column'; public const RENAME_CONSTRAINT = 'rename constraint'; public const RESET = 'reset'; public const RESET_ALL = 'reset all'; diff --git a/common/database/traits/database_rename_column.php b/common/database/traits/database_rename_column.php new file mode 100644 index 0000000..c21b0a7 --- /dev/null +++ b/common/database/traits/database_rename_column.php @@ -0,0 +1,113 @@ +rename_column = NULL; + return new c_base_return_true(); + } + + if (!is_string($from_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'from_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + if (!is_string($to_name)) { + $error = c_base_error::s_log(NULL, ['arguments' => [':{argument_name}' => 'to_name', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); + return c_base_return_error::s_false($error); + } + + $this->rename_column = [ + 'from' => $from_name, + 'to' => $to_name, + ]; + return new c_base_return_true(); + } + + /** + * Get the currently assigned name to rename from. + * + * @return c_base_return_string|c_base_return_null + * A name on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_rename_column_from_name() { + if (is_null($this->rename_column)) { + return new c_base_return_null(); + } + + if (is_string($this->rename_column['from'])) { + return c_base_return_string::s_new($this->rename_column['from']); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_column[from]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + /** + * Get the currently assigned name to rename to. + * + * @return c_base_return_string|c_base_return_null + * A name on success. + * NULL is returned if not set. + * NULL with the error bit set is returned on error. + */ + public function get_rename_column_to_name() { + if (is_null($this->rename_column)) { + return new c_base_return_null(); + } + + if (is_string($this->rename_column['to'])) { + return c_base_return_string::s_new($this->rename_column['to']); + } + + $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_column[to]', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); + return c_base_return_error::s_null($error); + } + + /** + * Perform the common build process for this trait. + * + * As an internal trait method, the caller is expected to perform any appropriate validation. + * + * @return string|null + * A string is returned on success. + * NULL is returned if there is nothing to process or there is an error. + */ + protected function p_do_build_rename_column() { + return c_database_string::RENAME_COLUMN . ' ' . $this->rename_column['from'] . ' ' . c_database_string::TO . $this->rename_column['to']; + } +} diff --git a/common/database/traits/database_rename_column_to.php b/common/database/traits/database_rename_column_to.php deleted file mode 100644 index 53c301b..0000000 --- a/common/database/traits/database_rename_column_to.php +++ /dev/null @@ -1,75 +0,0 @@ - [':{argument_name}' => 'rename_column_to', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_ARGUMENT); - return c_base_return_error::s_false($error); - } - - $this->rename_column_to = $rename_column_to; - return new c_base_return_true(); - } - - /** - * Get the currently assigned name to rename to. - * - * @return c_base_return_string|c_base_return_null - * A name on success. - * NULL is returned if not set (rename to is not to be used). - * NULL with the error bit set is returned on error. - */ - public function get_rename_column_to() { - if (is_null($this->rename_column_to)) { - return new c_base_return_null(); - } - - if (is_string($this->rename_column_to)) { - return c_base_return_string::s_new($this->rename_column_to); - } - - $error = c_base_error::s_log(NULL, ['arguments' => [':{variable_name}' => 'rename_column_to', ':{function_name}' => __CLASS__ . '->' . __FUNCTION__]], i_base_error_messages::INVALID_VARIABLE); - return c_base_return_error::s_null($error); - } - - /** - * Perform the common build process for this trait. - * - * As an internal trait method, the caller is expected to perform any appropriate validation. - * - * @return string|null - * A string is returned on success. - * NULL is returned if there is nothing to process or there is an error. - */ - protected function p_do_build_rename_column_to() { - return c_database_string::RENAME_COLUMN_TO . ' ' . $this->rename_to; - } -} -- 1.8.3.1