From 56c54dd8800399b16403ff9901e8a3048811a7aa Mon Sep 17 00:00:00 2001 From: El RIDO Date: Mon, 24 Jan 2022 17:48:27 +0100 Subject: [PATCH] prefer switch statements for complex logic, all comparing the same variable --- lib/Data/Database.php | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/Data/Database.php b/lib/Data/Database.php index 92aeec7..27e71c9 100644 --- a/lib/Data/Database.php +++ b/lib/Data/Database.php @@ -705,10 +705,14 @@ class Database extends AbstractData private static function _getPrimaryKeyClauses($key = 'dataid') { $main_key = $after_key = ''; - if (self::$_type === 'mysql' || self::$_type === 'oci') { - $after_key = ", PRIMARY KEY (\"$key\")"; - } else { - $main_key = ' PRIMARY KEY'; + switch (self::$_type) { + case 'mysql': + case 'oci': + $after_key = ", PRIMARY KEY (\"$key\")"; + break; + default: + $main_key = ' PRIMARY KEY'; + break; } return array($main_key, $after_key); } @@ -724,7 +728,14 @@ class Database extends AbstractData */ private static function _getDataType() { - return self::$_type === 'pgsql' ? 'TEXT' : (self::$_type === 'oci' ? 'CLOB' : 'BLOB'); + switch (self::$_type) { + case 'oci': + return 'CLOB'; + case 'pgsql': + return 'TEXT'; + default: + return 'BLOB'; + } } /** @@ -738,7 +749,14 @@ class Database extends AbstractData */ private static function _getAttachmentType() { - return self::$_type === 'pgsql' ? 'TEXT' : (self::$_type === 'oci' ? 'CLOB' : 'MEDIUMBLOB'); + switch (self::$_type) { + case 'oci': + return 'CLOB'; + case 'pgsql': + return 'TEXT'; + default: + return 'MEDIUMBLOB'; + } } /** @@ -752,7 +770,12 @@ class Database extends AbstractData */ private static function _getMetaType() { - return self::$_type === 'oci' ? 'VARCHAR2(4000)' : 'TEXT'; + switch (self::$_type) { + case 'oci': + return 'VARCHAR2(4000)'; + default: + return 'TEXT'; + } } /**