@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | 'sex' => 'sexes', |
| 75 | 75 | 'move' => 'moves'); |
| 76 | 76 | $lowercased_word = strtolower($word); |
| 77 | - foreach ($uncountable as $_uncountable){ |
|
| 78 | - if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ |
|
| 77 | + foreach ($uncountable as $_uncountable) { |
|
| 78 | + if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { |
|
| 79 | 79 | return $word; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | - foreach ($irregular as $_plural=> $_singular){ |
|
| 82 | + foreach ($irregular as $_plural=> $_singular) { |
|
| 83 | 83 | if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
| 84 | - return preg_replace('/('.$_plural.')$/i', substr($arr[0],0,1).substr($_singular,1), $word); |
|
| 84 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | foreach ($plural as $rule => $replacement) { |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | public function singularize($word) |
| 103 | 103 | { |
| 104 | - $singular = array ( |
|
| 104 | + $singular = array( |
|
| 105 | 105 | '/(quiz)zes$/i' => "$1", |
| 106 | 106 | '/(matr)ices$/i' => "$1ix", |
| 107 | 107 | '/(vert|ind)ices$/i' => "$1ex", |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | 'sex' => 'sexes', |
| 140 | 140 | 'move' => 'moves'); |
| 141 | 141 | $lowercased_word = strtolower($word); |
| 142 | - foreach ($uncountable as $_uncountable){ |
|
| 143 | - if(substr($lowercased_word,(-1*strlen($_uncountable))) == $_uncountable){ |
|
| 142 | + foreach ($uncountable as $_uncountable) { |
|
| 143 | + if (substr($lowercased_word, (-1*strlen($_uncountable))) == $_uncountable) { |
|
| 144 | 144 | return $word; |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - foreach ($irregular as $_plural=> $_singular){ |
|
| 147 | + foreach ($irregular as $_plural=> $_singular) { |
|
| 148 | 148 | if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
| 149 | - return preg_replace('/('.$_singular.')$/i', substr($arr[0],0,1).substr($_plural,1), $word); |
|
| 149 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | foreach ($singular as $rule => $replacement) { |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | * @license <https://opensource.org/license/MIT> MIT |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -namespace Laztopaz\potatoORM ; |
|
| 9 | +namespace Laztopaz\potatoORM; |
|
| 10 | 10 | |
| 11 | 11 | use Exception; |
| 12 | 12 | |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | self::loadEnv(); // load the environment variables |
| 26 | 26 | |
| 27 | - $this->databaseName = getenv('databaseName'); |
|
| 28 | - $this->databaseHost = getenv('databaseHost'); |
|
| 29 | - $this->databaseDriver = getenv('databaseDriver'); |
|
| 30 | - $this->databaseUsername = getenv('databaseUsername'); |
|
| 31 | - $this->databasePassword = getenv('databasePassword'); |
|
| 27 | + $this->databaseName = getenv('databaseName'); |
|
| 28 | + $this->databaseHost = getenv('databaseHost'); |
|
| 29 | + $this->databaseDriver = getenv('databaseDriver'); |
|
| 30 | + $this->databaseUsername = getenv('databaseUsername'); |
|
| 31 | + $this->databasePassword = getenv('databasePassword'); |
|
| 32 | 32 | |
| 33 | 33 | try { |
| 34 | 34 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | ]; |
| 41 | 41 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
| 42 | 42 | |
| 43 | - } catch(PDOException $e) { |
|
| 43 | + } catch (PDOException $e) { |
|
| 44 | 44 | |
| 45 | 45 | return $e->getMessage(); |
| 46 | 46 | } |
@@ -61,21 +61,21 @@ discard block |
||
| 61 | 61 | case 'mysql': |
| 62 | 62 | |
| 63 | 63 | // Set DSN |
| 64 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
| 64 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
| 65 | 65 | break; |
| 66 | 66 | case 'sqlite': |
| 67 | 67 | |
| 68 | 68 | // Set DSN |
| 69 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
| 69 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
| 70 | 70 | break; |
| 71 | 71 | case 'pgsql': |
| 72 | 72 | |
| 73 | 73 | // Set DSN |
| 74 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
| 74 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
| 75 | 75 | break; |
| 76 | 76 | default: |
| 77 | 77 | // Set DSN |
| 78 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
| 78 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
| 79 | 79 | } |
| 80 | 80 | return $dsn; |
| 81 | 81 | } |
@@ -44,11 +44,11 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function create($associative1DArray, $tableName, $dbConn = Null) |
| 46 | 46 | { |
| 47 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
| 47 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
| 48 | 48 | |
| 49 | 49 | if (count($unexpectedFields) > 0) |
| 50 | 50 | { |
| 51 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
| 51 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | unset($this->getColumnNames($this->model, $this->dbConnection)[0]); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $insertQuery = 'INSERT INTO '.$tableName; |
| 61 | 61 | |
| 62 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
| 62 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
| 63 | 63 | |
| 64 | 64 | foreach ($associative1DArray as $field => $value) { |
| 65 | 65 | |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | $splittedTableValues = implode(',', $FormValues); |
| 69 | 69 | |
| 70 | - $insertQuery.= ' ('.$TableValues.')'; |
|
| 70 | + $insertQuery .= ' ('.$TableValues.')'; |
|
| 71 | 71 | |
| 72 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
| 72 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
| 73 | 73 | |
| 74 | 74 | $executeQuery = $dbConn->exec($insertQuery); |
| 75 | 75 | |
| 76 | - return $executeQuery ? : false; |
|
| 76 | + return $executeQuery ?: false; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /* |
@@ -94,15 +94,15 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | unset($associative1DArray['id']); |
| 96 | 96 | |
| 97 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
| 97 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
| 98 | 98 | |
| 99 | 99 | if (count($unexpectedFields) > 0) { |
| 100 | 100 | |
| 101 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
| 101 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
| 105 | - foreach($associative1DArray as $field => $value) |
|
| 105 | + foreach ($associative1DArray as $field => $value) |
|
| 106 | 106 | { |
| 107 | 107 | $sql .= "`$field` = '$value'".","; |
| 108 | 108 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $boolResponse = $stmt->execute(); |
| 120 | 120 | |
| 121 | - return $boolResponse ? : false; |
|
| 121 | + return $boolResponse ?: false; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 139 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
| 140 | 140 | |
| 141 | 141 | try { |
| 142 | 142 | $stmt = $dbConn->prepare($sql); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | } |
| 151 | 151 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 152 | 152 | |
| 153 | - foreach($results as $result) { |
|
| 153 | + foreach ($results as $result) { |
|
| 154 | 154 | |
| 155 | 155 | array_push($tableData, $result); |
| 156 | 156 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | $boolResponse = $dbConn->exec($sql); |
| 177 | 177 | |
| 178 | - return $boolResponse ? : false; |
|
| 178 | + return $boolResponse ?: false; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | |
| 191 | 191 | foreach ($userSetterArray as $key => $val) |
| 192 | 192 | { |
| 193 | - if (!in_array($key,$tableColumn)) { |
|
| 193 | + if (!in_array($key, $tableColumn)) { |
|
| 194 | 194 | |
| 195 | 195 | $unexpectedFields[] = $key; |
| 196 | 196 | } |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | private function prepareUpdateQuery($sql) |
| 208 | 208 | { |
| 209 | - $splittedQuery = explode(",",$sql); |
|
| 209 | + $splittedQuery = explode(",", $sql); |
|
| 210 | 210 | |
| 211 | 211 | array_pop($splittedQuery); |
| 212 | 212 | |
| 213 | - $mergeData = implode(",",$splittedQuery); |
|
| 213 | + $mergeData = implode(",", $splittedQuery); |
|
| 214 | 214 | |
| 215 | 215 | return $mergeData; |
| 216 | 216 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | $returnedRowNumbers = $statement->rowCount(); |
| 246 | 246 | |
| 247 | - return $returnedRowNumbers ? true : false; |
|
| 247 | + return $returnedRowNumbers ? true : false; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param $conn |
| 257 | 257 | * @return array |
| 258 | 258 | */ |
| 259 | - public function getColumnNames($table, $dbConn = Null){ |
|
| 259 | + public function getColumnNames($table, $dbConn = Null) { |
|
| 260 | 260 | |
| 261 | 261 | $tableFields = []; |
| 262 | 262 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 277 | 277 | |
| 278 | - foreach($results as $result) { |
|
| 278 | + foreach ($results as $result) { |
|
| 279 | 279 | array_push($tableFields, $result['Field']); |
| 280 | 280 | } |
| 281 | 281 | |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | |
| 284 | 284 | } catch (PDOException $e) { |
| 285 | 285 | |
| 286 | - trigger_error('Could not connect to MySQL database. ' . $e->getMessage() , E_USER_ERROR); |
|
| 286 | + trigger_error('Could not connect to MySQL database. '.$e->getMessage(), E_USER_ERROR); |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | $conn = $this->dbConn; |
| 36 | 36 | } |
| 37 | 37 | $sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'('; |
| 38 | - $sql.= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )'; |
|
| 38 | + $sql .= ' id INT( 11 ) AUTO_INCREMENT PRIMARY KEY, name VARCHAR( 100 ), gender VARCHAR( 10 ), alias VARCHAR( 150 ) NOT NULL, class VARCHAR( 150 ), stack VARCHAR( 50 ) )'; |
|
| 39 | 39 | |
| 40 | 40 | return $conn->exec($sql); |
| 41 | 41 | |