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