| @@ -49,7 +49,7 @@ discard block | ||
| 49 | 49 | */ | 
| 50 | 50 | protected static function checkConnection($con) | 
| 51 | 51 |      { | 
| 52 | - if( is_null($con) ) | |
| 52 | + if (is_null($con)) | |
| 53 | 53 |          { | 
| 54 | 54 | $con = self::connect(); | 
| 55 | 55 | } | 
| @@ -64,11 +64,11 @@ discard block | ||
| 64 | 64 | * | 
| 65 | 65 | * @return bool | 
| 66 | 66 | */ | 
| 67 | - public function checkTableExist($table, $con=NULL) | |
| 67 | + public function checkTableExist($table, $con = NULL) | |
| 68 | 68 |      { | 
| 69 | 69 | $connection = $this->checkConnection($con); | 
| 70 | 70 |          $query = $connection->query("SELECT 1 FROM {$table} LIMIT 1"); | 
| 71 | - if( $query !== false ) | |
| 71 | + if ($query !== false) | |
| 72 | 72 |          { | 
| 73 | 73 | return true; | 
| 74 | 74 | } | 
| @@ -82,13 +82,13 @@ discard block | ||
| 82 | 82 | * | 
| 83 | 83 | * @return string | 
| 84 | 84 | */ | 
| 85 | - public static function checkTableName($tableName, $con=NULL) | |
| 85 | + public static function checkTableName($tableName, $con = NULL) | |
| 86 | 86 |      { | 
| 87 | 87 | $connection = self::checkConnection($con); | 
| 88 | 88 | // if( ! is_null($connection) ) | 
| 89 | 89 |          // { | 
| 90 | 90 |              $query = $connection->query("SELECT 1 FROM {$tableName} LIMIT 1"); | 
| 91 | - if( $query !== false ) | |
| 91 | + if ($query !== false) | |
| 92 | 92 |              { | 
| 93 | 93 | return $tableName; | 
| 94 | 94 | } | 
| @@ -106,13 +106,13 @@ discard block | ||
| 106 | 106 | * | 
| 107 | 107 | * @return string | 
| 108 | 108 | */ | 
| 109 | - protected static function checkColumn($tableName, $columnName, $con=NULL) | |
| 109 | + protected static function checkColumn($tableName, $columnName, $con = NULL) | |
| 110 | 110 |      { | 
| 111 | 111 | $connection = self::checkConnection($con); | 
| 112 | 112 | |
| 113 | 113 |              $result = $connection->prepare("SELECT {$columnName} FROM {$tableName}"); | 
| 114 | 114 | $result->execute(); | 
| 115 | - if ( ! $result->columnCount() ) | |
| 115 | + if ( ! $result->columnCount()) | |
| 116 | 116 |              { | 
| 117 | 117 | throw new ColumnNotExistExeption(); | 
| 118 | 118 | } | 
| @@ -132,11 +132,11 @@ discard block | ||
| 132 | 132 | $insertQuery = ""; | 
| 133 | 133 | $arraySize = sizeof($data); | 
| 134 | 134 | |
| 135 | - foreach ( $data as $key => $value ) | |
| 135 | + foreach ($data as $key => $value) | |
| 136 | 136 |          { | 
| 137 | 137 | $counter++; | 
| 138 | 138 | $insertQuery .= self::sanitize($key); | 
| 139 | - if( $arraySize > $counter ) | |
| 139 | + if ($arraySize > $counter) | |
| 140 | 140 | $insertQuery .= ", "; | 
| 141 | 141 | } | 
| 142 | 142 | return $insertQuery; | 
| @@ -155,11 +155,11 @@ discard block | ||
| 155 | 155 | $insertQuery = ""; | 
| 156 | 156 | $arraySize = sizeof($data); | 
| 157 | 157 | |
| 158 | - foreach ( $data as $key => $value ) | |
| 158 | + foreach ($data as $key => $value) | |
| 159 | 159 |          { | 
| 160 | 160 | $counter++; | 
| 161 | - $insertQuery .= "'".self::sanitize($value) ."'"; | |
| 162 | - if( $arraySize > $counter ) | |
| 161 | + $insertQuery .= "'".self::sanitize($value)."'"; | |
| 162 | + if ($arraySize > $counter) | |
| 163 | 163 | $insertQuery .= ", "; | 
| 164 | 164 | } | 
| 165 | 165 | return $insertQuery; | 
| @@ -178,12 +178,12 @@ discard block | ||
| 178 | 178 | $updateQuery = ""; | 
| 179 | 179 | $arraySize = sizeof($data); | 
| 180 | 180 | |
| 181 | - foreach ( $data as $key => $value ) | |
| 181 | + foreach ($data as $key => $value) | |
| 182 | 182 |          { | 
| 183 | 183 | $counter++; | 
| 184 | 184 | $columnName = self::checkColumn($tableName, self::sanitize($key)); | 
| 185 | - $updateQuery .= $columnName ." = '".self::sanitize($value)."'"; | |
| 186 | - if ( $arraySize > $counter ) | |
| 185 | + $updateQuery .= $columnName." = '".self::sanitize($value)."'"; | |
| 186 | + if ($arraySize > $counter) | |
| 187 | 187 |              { | 
| 188 | 188 | $updateQuery .= ", "; | 
| 189 | 189 | } | 
| @@ -212,14 +212,14 @@ discard block | ||
| 212 | 212 | $counter = 0; | 
| 213 | 213 | $arraySize = sizeof($data); | 
| 214 | 214 | |
| 215 | - foreach ( $data as $key => $value ) | |
| 215 | + foreach ($data as $key => $value) | |
| 216 | 216 |          { | 
| 217 | 217 | $counter++; | 
| 218 | 218 | $columnName = self::checkColumn($tableName, self::sanitize($key)); | 
| 219 | - $where .= $columnName ." = '".self::sanitize($value)."'"; | |
| 220 | - if ( $arraySize > $counter ) | |
| 219 | + $where .= $columnName." = '".self::sanitize($value)."'"; | |
| 220 | + if ($arraySize > $counter) | |
| 221 | 221 |              { | 
| 222 | - $where .= " " . $condition . " "; | |
| 222 | + $where .= " ".$condition." "; | |
| 223 | 223 | } | 
| 224 | 224 | } | 
| 225 | 225 | |
| @@ -237,16 +237,16 @@ discard block | ||
| 237 | 237 | try | 
| 238 | 238 |          { | 
| 239 | 239 | $arraySize = sizeof($data); | 
| 240 | - if( $arraySize > 1 && $condition == NULL) | |
| 240 | + if ($arraySize > 1 && $condition == NULL) | |
| 241 | 241 |              { | 
| 242 | 242 | $query = "Please Supply the condition"; | 
| 243 | 243 | } | 
| 244 | 244 | else | 
| 245 | 245 |              { | 
| 246 | 246 | $columnName = self::whereAndClause($tableName, $data, $condition); | 
| 247 | - $query = "SELECT * FROM $tableName WHERE $columnName"; | |
| 247 | + $query = "SELECT * FROM $tableName WHERE $columnName"; | |
| 248 | 248 | } | 
| 249 | -        } catch ( PDOException $e ) { | |
| 249 | +        } catch (PDOException $e) { | |
| 250 | 250 | $query = $e->getMessage(); | 
| 251 | 251 | } | 
| 252 | 252 | |
| @@ -260,7 +260,7 @@ discard block | ||
| 260 | 260 | */ | 
| 261 | 261 | public function insertQuery($tableName) | 
| 262 | 262 |      { | 
| 263 | - $data = ( array )$this; | |
| 263 | + $data = (array)$this; | |
| 264 | 264 | array_shift($data); | 
| 265 | 265 | |
| 266 | 266 | $columnNames = self::buildColumn($data); | 
| @@ -277,11 +277,11 @@ discard block | ||
| 277 | 277 | */ | 
| 278 | 278 | public function updateQuery($tableName) | 
| 279 | 279 |      { | 
| 280 | - $data = ( array ) $this; | |
| 281 | - $data = array_slice ($data, 2); | |
| 280 | + $data = (array)$this; | |
| 281 | + $data = array_slice($data, 2); | |
| 282 | 282 | |
| 283 | 283 | $values = self::buildClause($tableName, $data); | 
| 284 | -        $updateQuery = "UPDATE $tableName SET {$values} WHERE id = ". self::sanitize($this->id); | |
| 284 | +        $updateQuery = "UPDATE $tableName SET {$values} WHERE id = ".self::sanitize($this->id); | |
| 285 | 285 | |
| 286 | 286 | return $updateQuery; | 
| 287 | 287 | } | 
| @@ -25,6 +25,6 @@ | ||
| 25 | 25 | */ | 
| 26 | 26 | public function errorMessage() | 
| 27 | 27 |      { | 
| 28 | - return "Error: " . $this->getMessage(); | |
| 28 | + return "Error: ".$this->getMessage(); | |
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | \ No newline at end of file | 
| @@ -81,15 +81,15 @@ discard block | ||
| 81 | 81 | |
| 82 | 82 | $lowercased_word = strtolower($word); | 
| 83 | 83 | |
| 84 | -        foreach ($uncountable as $_uncountable){ | |
| 85 | -            if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ | |
| 84 | +        foreach ($uncountable as $_uncountable) { | |
| 85 | +            if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { | |
| 86 | 86 | return $word; | 
| 87 | 87 | } | 
| 88 | 88 | } | 
| 89 | 89 | |
| 90 | -        foreach ($irregular as $_plural=> $_singular){ | |
| 90 | +        foreach ($irregular as $_plural=> $_singular) { | |
| 91 | 91 |              if (preg_match('/('.$_plural.')$/i', $word, $arr)) { | 
| 92 | -                return preg_replace('/('.$_plural.')$/i', substr($arr[0],0,1).substr($_singular,1), $word); | |
| 92 | +                return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); | |
| 93 | 93 | } | 
| 94 | 94 | } | 
| 95 | 95 | |
| @@ -111,7 +111,7 @@ discard block | ||
| 111 | 111 | */ | 
| 112 | 112 | public function singularize($word) | 
| 113 | 113 |      { | 
| 114 | - $singular = array ( | |
| 114 | + $singular = array( | |
| 115 | 115 | '/(quiz)zes$/i' => "$1", | 
| 116 | 116 | '/(matr)ices$/i' => "$1ix", | 
| 117 | 117 | '/(vert|ind)ices$/i' => "$1ex", | 
| @@ -152,15 +152,15 @@ discard block | ||
| 152 | 152 | 'move' => 'moves'); | 
| 153 | 153 | |
| 154 | 154 | $lowercased_word = strtolower($word); | 
| 155 | -        foreach ($uncountable as $_uncountable){ | |
| 156 | -            if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ | |
| 155 | +        foreach ($uncountable as $_uncountable) { | |
| 156 | +            if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { | |
| 157 | 157 | return $word; | 
| 158 | 158 | } | 
| 159 | 159 | } | 
| 160 | 160 | |
| 161 | -        foreach ($irregular as $_plural=> $_singular){ | |
| 161 | +        foreach ($irregular as $_plural=> $_singular) { | |
| 162 | 162 |              if (preg_match('/('.$_singular.')$/i', $word, $arr)) { | 
| 163 | -                return preg_replace('/('.$_singular.')$/i', substr($arr[0],0,1).substr($_plural,1), $word); | |
| 163 | +                return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); | |
| 164 | 164 | } | 
| 165 | 165 | } | 
| 166 | 166 | |
| @@ -25,13 +25,13 @@ discard block | ||
| 25 | 25 | * | 
| 26 | 26 | * @return array | 
| 27 | 27 | */ | 
| 28 | - public function field($type, $fieldName, $length=NULL) | |
| 28 | + public function field($type, $fieldName, $length = NULL) | |
| 29 | 29 |      { | 
| 30 | -        if(is_null($length)){ | |
| 31 | - $this->fieldDescription[] = $type ." ".$fieldName; | |
| 32 | - }else | |
| 30 | +        if (is_null($length)) { | |
| 31 | + $this->fieldDescription[] = $type." ".$fieldName; | |
| 32 | + } else | |
| 33 | 33 |          { | 
| 34 | - $this->fieldDescription[] = $type ." ".$fieldName." ".$length; | |
| 34 | + $this->fieldDescription[] = $type." ".$fieldName." ".$length; | |
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | 37 | } | 
| @@ -49,12 +49,12 @@ discard block | ||
| 49 | 49 | $callback = function($fieldName) use (&$query) | 
| 50 | 50 |          { | 
| 51 | 51 |              $e = explode(" ", $fieldName); | 
| 52 | - if(sizeof($e) == 2) | |
| 52 | + if (sizeof($e) == 2) | |
| 53 | 53 |              { | 
| 54 | - $query .= $this->$e[0]($e[1], 20) .", ".PHP_EOL; | |
| 55 | - }else | |
| 54 | + $query .= $this->$e[0]($e[1], 20).", ".PHP_EOL; | |
| 55 | + } else | |
| 56 | 56 |              { | 
| 57 | - $query .= $this->$e[0]($e[1], $e[2]) .", ".PHP_EOL; | |
| 57 | + $query .= $this->$e[0]($e[1], $e[2]).", ".PHP_EOL; | |
| 58 | 58 | } | 
| 59 | 59 | }; | 
| 60 | 60 | array_walk($this->fieldDescription, $callback); | 
| @@ -82,7 +82,7 @@ discard block | ||
| 82 | 82 | */ | 
| 83 | 83 | public function createTable($tablename, $connection = NULL) | 
| 84 | 84 |      { | 
| 85 | - if(is_null($connection)) | |
| 85 | + if (is_null($connection)) | |
| 86 | 86 |          { | 
| 87 | 87 | $connection = DatabaseQuery::connect(); | 
| 88 | 88 | } | 
| @@ -90,11 +90,11 @@ discard block | ||
| 90 | 90 |          { | 
| 91 | 91 | $sqlQuery = self::sanitizeQuery($tablename); | 
| 92 | 92 | $query = $connection->prepare($sqlQuery); | 
| 93 | - if($query->execute()) | |
| 93 | + if ($query->execute()) | |
| 94 | 94 |              { | 
| 95 | 95 | return true; | 
| 96 | 96 | } | 
| 97 | -        }catch(PDOException $e){ | |
| 97 | +        } catch (PDOException $e) { | |
| 98 | 98 | return $e->getMessage(); | 
| 99 | 99 | } | 
| 100 | 100 | } | 
| @@ -116,7 +116,7 @@ discard block | ||
| 116 | 116 | */ | 
| 117 | 117 | public function strings($value, $length) | 
| 118 | 118 |      { | 
| 119 | -        return $value ." varchar (".$length.") NOT NULL"; | |
| 119 | +        return $value." varchar (".$length.") NOT NULL"; | |
| 120 | 120 | } | 
| 121 | 121 | |
| 122 | 122 | /** | 
| @@ -201,6 +201,6 @@ discard block | ||
| 201 | 201 | $apend = 'timestamp'; | 
| 202 | 202 | break; | 
| 203 | 203 | } | 
| 204 | - return $value . " " . $apend . " NOT NULL"; | |
| 204 | + return $value." ".$apend." NOT NULL"; | |
| 205 | 205 | } | 
| 206 | 206 | } | 
| 207 | 207 | \ No newline at end of file | 
| @@ -11,9 +11,9 @@ | ||
| 11 | 11 | |
| 12 | 12 | interface DatabaseQueryInterface | 
| 13 | 13 |  { | 
| 14 | - public function checkTableExist($table, $con=NULL); | |
| 14 | + public function checkTableExist($table, $con = NULL); | |
| 15 | 15 | |
| 16 | - public static function checkTableName($table, $dbConnection=NULL); | |
| 16 | + public static function checkTableName($table, $dbConnection = NULL); | |
| 17 | 17 | |
| 18 | 18 | public static function selectQuery($tableName, $field, $value, $connection); | 
| 19 | 19 | |
| @@ -25,6 +25,6 @@ | ||
| 25 | 25 | */ | 
| 26 | 26 | public function errorMessage() | 
| 27 | 27 |      { | 
| 28 | - return "Error: " . $this->getMessage(); | |
| 28 | + return "Error: ".$this->getMessage(); | |
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | \ No newline at end of file | 
| @@ -25,6 +25,6 @@ | ||
| 25 | 25 | */ | 
| 26 | 26 | public function errorMessage() | 
| 27 | 27 |      { | 
| 28 | - return "Error: " . $this->getMessage(); | |
| 28 | + return "Error: ".$this->getMessage(); | |
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | \ No newline at end of file | 
| @@ -25,6 +25,6 @@ | ||
| 25 | 25 | */ | 
| 26 | 26 | public function errorMessage() | 
| 27 | 27 |      { | 
| 28 | - return "Error: " . $this->getMessage(); | |
| 28 | + return "Error: ".$this->getMessage(); | |
| 29 | 29 | } | 
| 30 | 30 | } | 
| 31 | 31 | \ No newline at end of file | 
| @@ -47,7 +47,7 @@ discard block | ||
| 47 | 47 |              { | 
| 48 | 48 | parent::__construct($this->mysqlConnectionString(), $this->user, $this->password); | 
| 49 | 49 | } | 
| 50 | - elseif($this->driver === 'sqlite') | |
| 50 | + elseif ($this->driver === 'sqlite') | |
| 51 | 51 |              { | 
| 52 | 52 | parent::__construct($this->sqlitConnectionString()); | 
| 53 | 53 | } | 
| @@ -63,7 +63,7 @@ discard block | ||
| 63 | 63 | */ | 
| 64 | 64 | protected function pgsqlConnectionString() | 
| 65 | 65 |      { | 
| 66 | - return $this->driver . ':host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';user=' . $this->user . ';password=' . $this->password; | |
| 66 | + return $this->driver.':host='.$this->host.';port='.$this->port.';dbname='.$this->dbname.';user='.$this->user.';password='.$this->password; | |
| 67 | 67 | } | 
| 68 | 68 | |
| 69 | 69 | /** | 
| @@ -73,7 +73,7 @@ discard block | ||
| 73 | 73 | */ | 
| 74 | 74 | protected function mysqlConnectionString() | 
| 75 | 75 |      { | 
| 76 | - return $this->driver . ':host=' . $this->host . ';dbname=' . $this->dbname . ';charset=utf8mb4'; | |
| 76 | + return $this->driver.':host='.$this->host.';dbname='.$this->dbname.';charset=utf8mb4'; | |
| 77 | 77 | } | 
| 78 | 78 | |
| 79 | 79 | /** | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | */ | 
| 84 | 84 | protected function sqlitConnectionString() | 
| 85 | 85 |      { | 
| 86 | - return $this->driver . ':' . $this->sqlitePath; | |
| 86 | + return $this->driver.':'.$this->sqlitePath; | |
| 87 | 87 | } | 
| 88 | 88 | |
| 89 | 89 | /** | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 | */ | 
| 92 | 92 | protected function loadEnv() | 
| 93 | 93 |      { | 
| 94 | -        if( ! getenv("APP_ENV" !== "production")) | |
| 94 | +        if ( ! getenv("APP_ENV" !== "production")) | |
| 95 | 95 |          { | 
| 96 | 96 | $dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']); | 
| 97 | 97 | $dotenv->load(); |