@@ -14,7 +14,6 @@ |
||
14 | 14 | use Laztopaz\potatoORM\NoRecordFoundException; |
15 | 15 | use Laztopaz\potatoORM\NoRecordInsertionException; |
16 | 16 | use Laztopaz\potatoORM\NullArgumentPassedToFunction; |
17 | -use Laztopaz\potatoORM\WrongArgumentException; |
|
18 | 17 | use Laztopaz\potatoORM\NoArgumentPassedToFunctionException; |
19 | 18 | use Laztopaz\potatoORM\EmptyArrayException; |
20 | 19 |
@@ -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 |
@@ -8,7 +8,6 @@ |
||
8 | 8 | |
9 | 9 | namespace Laztopaz\potatoORM; |
10 | 10 | |
11 | -use PDO; |
|
12 | 11 | use Laztopaz\potatoORM\TableNotCreatedException; |
13 | 12 | |
14 | 13 | class DatabaseHelper { |
@@ -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 | } |
@@ -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 |
@@ -9,10 +9,8 @@ |
||
9 | 9 | namespace Laztopaz\potatoORM; |
10 | 10 | |
11 | 11 | use PDO; |
12 | -use Laztopaz\potatoORM\DatabaseHelper; |
|
13 | 12 | use Laztopaz\potatoORM\TableFieldUndefinedException; |
14 | 13 | use Laztopaz\potatoORM\EmptyArrayException; |
15 | - |
|
16 | 14 | use Laztopaz\potatoORM\NoRecordDeletionException; |
17 | 15 | use Laztopaz\potatoORM\NoRecordInsertionException; |
18 | 16 | use Laztopaz\potatoORM\NoRecordUpdateException; |
@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function create($associative1DArray, $tableName, $dbConn = Null) { |
44 | 44 | $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
45 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
45 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
46 | 46 | if (count($unexpectedFields) > 0) { |
47 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as table field"); |
|
47 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
|
48 | 48 | } |
49 | 49 | unset($associative1DArray[0]); |
50 | 50 | if (is_null($dbConn)) { |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | |
56 | 56 | private function insertRecord($dbConn, $tableName, $associative1DArray) { |
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 | 66 | |
67 | 67 | if ($executeQuery) { |
@@ -85,12 +85,12 @@ discard block |
||
85 | 85 | } |
86 | 86 | $updateSql = "UPDATE `$tableName` SET "; |
87 | 87 | unset($associative1DArray['id']); |
88 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
88 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
89 | 89 | |
90 | 90 | if (count($unexpectedFields) > 0) { |
91 | 91 | throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as table field"); |
92 | 92 | } |
93 | - foreach($associative1DArray as $field => $value) { |
|
93 | + foreach ($associative1DArray as $field => $value) { |
|
94 | 94 | $sql .= "`$field` = '$value'".","; |
95 | 95 | } |
96 | 96 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | if (is_null($dbConn)) { |
124 | 124 | $dbConn = new DatabaseConnection(); |
125 | 125 | } |
126 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
126 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
127 | 127 | |
128 | 128 | try { |
129 | 129 | $stmt = $dbConn->prepare($sql); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | } |
136 | 136 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
137 | 137 | |
138 | - foreach($results as $result) { |
|
138 | + foreach ($results as $result) { |
|
139 | 139 | array_push($tableData, $result); |
140 | 140 | } |
141 | 141 | return $tableData; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | { |
175 | 175 | $unexpectedFields = []; |
176 | 176 | foreach ($userSetterArray as $key => $val) { |
177 | - if (!in_array($key,$tableColumn)) { |
|
177 | + if (!in_array($key, $tableColumn)) { |
|
178 | 178 | $unexpectedFields[] = $key; |
179 | 179 | } |
180 | 180 | } |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function prepareUpdateQuery($sql) |
190 | 190 | { |
191 | - $splittedQuery = explode(",",$sql); |
|
191 | + $splittedQuery = explode(",", $sql); |
|
192 | 192 | array_pop($splittedQuery); |
193 | - $mergeData = implode(",",$splittedQuery); |
|
193 | + $mergeData = implode(",", $splittedQuery); |
|
194 | 194 | return $mergeData; |
195 | 195 | } |
196 | 196 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $statement->execute(); |
216 | 216 | $returnedRowNumbers = $statement->rowCount(); |
217 | 217 | |
218 | - return $returnedRowNumbers ? true : false; |
|
218 | + return $returnedRowNumbers ? true : false; |
|
219 | 219 | } |
220 | 220 | throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
221 | 221 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $stmt->execute(); |
240 | 240 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
241 | 241 | |
242 | - foreach($results as $result) { |
|
242 | + foreach ($results as $result) { |
|
243 | 243 | array_push($tableFields, $result['Field']); |
244 | 244 | } |
245 | 245 | return $tableFields; |
@@ -74,14 +74,14 @@ |
||
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) { |