]> Kevux Git Server - koopa/commitdiff
Cleanup: Rename 'rename column to' to 'rename column'
authorKevin Day <thekevinday@gmail.com>
Mon, 3 Dec 2018 04:16:54 +0000 (22:16 -0600)
committerKevin Day <thekevinday@gmail.com>
Mon, 3 Dec 2018 04:16:54 +0000 (22:16 -0600)
common/database/classes/database_string.php
common/database/traits/database_rename_column.php [new file with mode: 0644]
common/database/traits/database_rename_column_to.php [deleted file]

index adf788657aae092c45eb3c604274b97ab075881f..f61b9a8faefd4bf28cebc3c71ff5be4b2461e419 100644 (file)
@@ -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 (file)
index 0000000..c21b0a7
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/**
+ * @file
+ * Provides traits for specific Postgesql Queries.
+ *
+ * These traits are associated with actions.
+ *
+ * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
+ */
+namespace n_koopa;
+
+require_once('common/base/classes/base_error.php');
+require_once('common/base/classes/base_return.php');
+
+/**
+ * Provide the sql RENAME COLUMN functionality.
+ */
+trait t_database_rename_column {
+  protected $rename_column;
+
+  /**
+   * Set the RENAME COLUMN settings.
+   *
+   * @param string|null $from_name
+   *   The column name to rename from.
+   *   Set to NULL to disable.
+   * @param string|null $to_name
+   *   The column name to rename to.
+   *   Required when $from_name is not NULL.
+   *   Ignored when $from_name is NULL.
+   *
+   * @return c_base_return_status
+   *   TRUE on success, FALSE otherwise.
+   *   FALSE with the error bit set is returned on error.
+   */
+  public function set_rename_column($from_name, $to_name = NULL) {
+    if (is_null($from_name)) {
+      $this->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 (file)
index 53c301b..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-<?php
-/**
- * @file
- * Provides traits for specific Postgesql Queries.
- *
- * These traits are associated with actions.
- *
- * @see: https://www.postgresql.org/docs/current/static/sql-commands.html
- */
-namespace n_koopa;
-
-require_once('common/base/classes/base_error.php');
-require_once('common/base/classes/base_return.php');
-
-/**
- * Provide the sql RENAME COLUMN TO functionality.
- */
-trait t_database_rename_column_to {
-  protected $rename_column_to;
-
-  /**
-   * Set the RENAME COLUMN TO settings.
-   *
-   * @param string|null $rename_column_to
-   *   The name to rename to.
-   *   Set to NULL to disable.
-   *
-   * @return c_base_return_status
-   *   TRUE on success, FALSE otherwise.
-   *   FALSE with the error bit set is returned on error.
-   */
-  public function set_rename_column_to($rename_column_to) {
-    if (!is_null($rename_column_to) && !is_string($rename_column_to)) {
-      $error = c_base_error::s_log(NULL, ['arguments' => [':{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;
-  }
-}