@@ -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 |
@@ -22,11 +22,11 @@ discard block |
||
22 | 22 | public function __construct() |
23 | 23 | { |
24 | 24 | $this->loadEnv(); // load the environment variables |
25 | - $this->databaseName = getenv('databaseName'); |
|
26 | - $this->databaseHost = getenv('databaseHost'); |
|
27 | - $this->databaseDriver = getenv('databaseDriver'); |
|
28 | - $this->databaseUsername = getenv('databaseUsername'); |
|
29 | - $this->databasePassword = getenv('databasePassword'); |
|
25 | + $this->databaseName = getenv('databaseName'); |
|
26 | + $this->databaseHost = getenv('databaseHost'); |
|
27 | + $this->databaseDriver = getenv('databaseDriver'); |
|
28 | + $this->databaseUsername = getenv('databaseUsername'); |
|
29 | + $this->databasePassword = getenv('databasePassword'); |
|
30 | 30 | |
31 | 31 | try { |
32 | 32 | $options = [ |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION |
35 | 35 | ]; |
36 | 36 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
37 | - } catch(PDOException $e) { |
|
37 | + } catch (PDOException $e) { |
|
38 | 38 | return $e->getMessage(); |
39 | 39 | } |
40 | 40 | } |
@@ -51,20 +51,20 @@ discard block |
||
51 | 51 | { |
52 | 52 | case 'mysql': |
53 | 53 | // Set DSN |
54 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
54 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
55 | 55 | break; |
56 | 56 | case 'sqlite': |
57 | 57 | // Set DSN |
58 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
58 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
59 | 59 | break; |
60 | 60 | case 'pgsql': |
61 | 61 | |
62 | 62 | // Set DSN |
63 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
63 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
64 | 64 | break; |
65 | 65 | default: |
66 | 66 | // Set DSN |
67 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
67 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
68 | 68 | } |
69 | 69 | return $dsn; |
70 | 70 | } |
@@ -41,9 +41,9 @@ discard block |
||
41 | 41 | { |
42 | 42 | $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
43 | 43 | |
44 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
44 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
45 | 45 | if (count($unexpectedFields) > 0) { |
46 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
46 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
47 | 47 | } |
48 | 48 | unset($tableFields[0]); |
49 | 49 | if (is_null($dbConn)) { |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | private function insertRecord($dbConn, $tableName, $associative1DArray) |
56 | 56 | { |
57 | 57 | $insertQuery = 'INSERT INTO '.$tableName; |
58 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
58 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
59 | 59 | foreach ($associative1DArray as $field => $value) { |
60 | 60 | $FormValues[] = "'".trim(addslashes($value))."'"; |
61 | 61 | } |
62 | 62 | $splittedTableValues = implode(',', $FormValues); |
63 | - $insertQuery.= ' ('.$TableValues.')'; |
|
64 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
63 | + $insertQuery .= ' ('.$TableValues.')'; |
|
64 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
65 | 65 | $executeQuery = $dbConn->exec($insertQuery); |
66 | - return $executeQuery ? : false; |
|
66 | + return $executeQuery ?: false; |
|
67 | 67 | |
68 | 68 | } |
69 | 69 | |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | } |
81 | 81 | $updateSql = "UPDATE `$tableName` SET "; |
82 | 82 | unset($associative1DArray['id']); |
83 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
83 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
84 | 84 | |
85 | 85 | if (count($unexpectedFields) > 0) { |
86 | 86 | throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
87 | 87 | } |
88 | - foreach($associative1DArray as $field => $value) { |
|
88 | + foreach ($associative1DArray as $field => $value) { |
|
89 | 89 | $sql .= "`$field` = '$value'".","; |
90 | 90 | } |
91 | 91 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | $stmt = $dbConn->prepare($updateSql); |
98 | 98 | $boolResponse = $stmt->execute(); |
99 | - return $boolResponse ? : false; |
|
99 | + return $boolResponse ?: false; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if (is_null($dbConn)) { |
112 | 112 | $dbConn = new DatabaseConnection(); |
113 | 113 | } |
114 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
114 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
115 | 115 | |
116 | 116 | try { |
117 | 117 | $stmt = $dbConn->prepare($sql); |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
125 | 125 | |
126 | - foreach($results as $result) { |
|
126 | + foreach ($results as $result) { |
|
127 | 127 | array_push($tableData, $result); |
128 | 128 | } |
129 | 129 | return $tableData; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
144 | 144 | $boolResponse = $dbConn->exec($sql); |
145 | - return $boolResponse ? : false; |
|
145 | + return $boolResponse ?: false; |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | { |
156 | 156 | $unexpectedFields = []; |
157 | 157 | foreach ($userSetterArray as $key => $val) { |
158 | - if (!in_array($key,$tableColumn)) { |
|
158 | + if (!in_array($key, $tableColumn)) { |
|
159 | 159 | $unexpectedFields[] = $key; |
160 | 160 | } |
161 | 161 | } |
@@ -169,9 +169,9 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function prepareUpdateQuery($sql) |
171 | 171 | { |
172 | - $splittedQuery = explode(",",$sql); |
|
172 | + $splittedQuery = explode(",", $sql); |
|
173 | 173 | array_pop($splittedQuery); |
174 | - $mergeData = implode(",",$splittedQuery); |
|
174 | + $mergeData = implode(",", $splittedQuery); |
|
175 | 175 | return $mergeData; |
176 | 176 | } |
177 | 177 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $statement->execute(); |
198 | 198 | $returnedRowNumbers = $statement->rowCount(); |
199 | 199 | |
200 | - return $returnedRowNumbers ? true : false; |
|
200 | + return $returnedRowNumbers ? true : false; |
|
201 | 201 | } |
202 | 202 | throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
203 | 203 | } |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | $stmt->execute(); |
222 | 222 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
223 | 223 | |
224 | - foreach($results as $result) { |
|
224 | + foreach ($results as $result) { |
|
225 | 225 | array_push($tableFields, $result['Field']); |
226 | 226 | } |
227 | 227 | return $tableFields; |
@@ -35,7 +35,7 @@ |
||
35 | 35 | } |
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 | throw TableNotCreatedException::tableNotCreatedException("Check your database connection"); |