@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | /** |
120 | 120 | * This method find a record by id |
121 | 121 | * @params int id |
122 | - * @return Object |
|
122 | + * @return BaseClass |
|
123 | 123 | * @throws NoArgumentPassedToFunctionException |
124 | 124 | */ |
125 | 125 | public static function find($id) |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | /** |
172 | 172 | * This method return the current class name |
173 | 173 | * $params void |
174 | - * @return classname |
|
174 | + * @return string|false |
|
175 | 175 | */ |
176 | 176 | public static function getClassName() |
177 | 177 | { |
@@ -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 |
@@ -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 |
@@ -9,7 +9,6 @@ |
||
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 | 14 |
@@ -22,6 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | /** |
24 | 24 | * This is a constructor; a default method that will be called automatically during class instantiation |
25 | + * @param string|false $modelClassName |
|
25 | 26 | */ |
26 | 27 | public function __construct($modelClassName, $dbConn = Null) |
27 | 28 | { |
@@ -36,7 +37,8 @@ discard block |
||
36 | 37 | /** |
37 | 38 | * This method create a record and store it in a table row |
38 | 39 | * @params associative array, string tablename |
39 | - * @return boolean true or false |
|
40 | + * @param string|false $tableName |
|
41 | + * @return boolean|null true or false |
|
40 | 42 | */ |
41 | 43 | public function create($associative1DArray, $tableName, $dbConn = Null) |
42 | 44 | { |
@@ -79,6 +81,10 @@ discard block |
||
79 | 81 | * @params: $updateParams, $tableName, $associative1DArray |
80 | 82 | * @return boolean true or false |
81 | 83 | */ |
84 | + |
|
85 | + /** |
|
86 | + * @param string|false $tableName |
|
87 | + */ |
|
82 | 88 | public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
83 | 89 | { |
84 | 90 | $sql = ""; |
@@ -112,6 +118,7 @@ discard block |
||
112 | 118 | /** |
113 | 119 | * This method retrieves record from a table |
114 | 120 | * @params int id, string tableName |
121 | + * @param string|false $tableName |
|
115 | 122 | * @return array |
116 | 123 | */ |
117 | 124 | public static function read($id, $tableName, $dbConn = Null) |
@@ -143,6 +150,7 @@ discard block |
||
143 | 150 | /** |
144 | 151 | * This method deletes a record from a table row |
145 | 152 | * @params int id, string tableName |
153 | + * @param string|false $tableName |
|
146 | 154 | * @return boolean true or false |
147 | 155 | */ |
148 | 156 | public static function delete($id, $tableName, $dbConn = Null) |
@@ -177,7 +185,7 @@ discard block |
||
177 | 185 | |
178 | 186 | /** |
179 | 187 | * This method returns sql query |
180 | - * @param $sql |
|
188 | + * @param string $sql |
|
181 | 189 | * @return string |
182 | 190 | */ |
183 | 191 | public function prepareUpdateQuery($sql) |
@@ -219,6 +227,7 @@ discard block |
||
219 | 227 | * This method returns column fields of a particular table |
220 | 228 | * @param $table |
221 | 229 | * @param $conn |
230 | + * @param DatabaseConnection $dbConn |
|
222 | 231 | * @return array |
223 | 232 | */ |
224 | 233 | public function getColumnNames($table, $dbConn = Null) { |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | { |
43 | 43 | $tableFields = $this->getColumnNames($this->model, $this->dbConnection); |
44 | 44 | |
45 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields,$associative1DArray); |
|
45 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
|
46 | 46 | |
47 | 47 | if (count($unexpectedFields) > 0) { |
48 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); |
|
48 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
|
49 | 49 | } |
50 | 50 | unset($tableFields[0]); |
51 | 51 | |
@@ -60,17 +60,17 @@ discard block |
||
60 | 60 | private function insertRecord($dbConn, $tableName, $associative1DArray) { |
61 | 61 | |
62 | 62 | $insertQuery = 'INSERT INTO '.$tableName; |
63 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
63 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
64 | 64 | foreach ($associative1DArray as $field => $value) { |
65 | 65 | |
66 | 66 | $FormValues[] = "'".trim(addslashes($value))."'"; |
67 | 67 | } |
68 | 68 | $splittedTableValues = implode(',', $FormValues); |
69 | - $insertQuery.= ' ('.$TableValues.')'; |
|
70 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
69 | + $insertQuery .= ' ('.$TableValues.')'; |
|
70 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
71 | 71 | $executeQuery = $dbConn->exec($insertQuery); |
72 | 72 | |
73 | - return $executeQuery ? : false; |
|
73 | + return $executeQuery ?: false; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /* |
@@ -87,13 +87,13 @@ discard block |
||
87 | 87 | |
88 | 88 | $updateSql = "UPDATE `$tableName` SET "; |
89 | 89 | unset($associative1DArray['id']); |
90 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection),$associative1DArray); |
|
90 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->getColumnNames($this->model, $this->dbConnection), $associative1DArray); |
|
91 | 91 | |
92 | 92 | if (count($unexpectedFields) > 0) { |
93 | 93 | throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); |
94 | 94 | } |
95 | 95 | |
96 | - foreach($associative1DArray as $field => $value) { |
|
96 | + foreach ($associative1DArray as $field => $value) { |
|
97 | 97 | $sql .= "`$field` = '$value'".","; |
98 | 98 | } |
99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | $stmt = $dbConn->prepare($updateSql); |
106 | 106 | $boolResponse = $stmt->execute(); |
107 | 107 | |
108 | - return $boolResponse ? : false; |
|
108 | + return $boolResponse ?: false; |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | if (is_null($dbConn)) { |
121 | 121 | $dbConn = new DatabaseConnection(); |
122 | 122 | } |
123 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
123 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; |
|
124 | 124 | |
125 | 125 | try { |
126 | 126 | $stmt = $dbConn->prepare($sql); |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | } |
133 | 133 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
134 | 134 | |
135 | - foreach($results as $result) { |
|
135 | + foreach ($results as $result) { |
|
136 | 136 | array_push($tableData, $result); |
137 | 137 | } |
138 | 138 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $sql = 'DELETE FROM '.$tableName.' WHERE id = '.$id; |
153 | 153 | $boolResponse = $dbConn->exec($sql); |
154 | 154 | |
155 | - return $boolResponse ? : false; |
|
155 | + return $boolResponse ?: false; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | $unexpectedFields = []; |
167 | 167 | |
168 | 168 | foreach ($userSetterArray as $key => $val) { |
169 | - if (!in_array($key,$tableColumn)) { |
|
169 | + if (!in_array($key, $tableColumn)) { |
|
170 | 170 | |
171 | 171 | $unexpectedFields[] = $key; |
172 | 172 | } |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function prepareUpdateQuery($sql) |
183 | 183 | { |
184 | - $splittedQuery = explode(",",$sql); |
|
184 | + $splittedQuery = explode(",", $sql); |
|
185 | 185 | array_pop($splittedQuery); |
186 | - $mergeData = implode(",",$splittedQuery); |
|
186 | + $mergeData = implode(",", $splittedQuery); |
|
187 | 187 | |
188 | 188 | return $mergeData; |
189 | 189 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $statement = $dbConn->prepare($sql); |
209 | 209 | $statement->execute(); |
210 | 210 | $returnedRowNumbers = $statement->rowCount(); |
211 | - return $returnedRowNumbers ? true : false; |
|
211 | + return $returnedRowNumbers ? true : false; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | throw EmptyArrayException::checkEmptyArrayException("Array Expected: parameter passed to this function is not an array"); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $stmt->execute(); |
235 | 235 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); |
236 | 236 | |
237 | - foreach($results as $result) { |
|
237 | + foreach ($results as $result) { |
|
238 | 238 | array_push($tableFields, $result['Field']); |
239 | 239 | } |
240 | 240 | return $tableFields; |
@@ -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 | $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 |
@@ -12,8 +12,8 @@ |
||
12 | 12 | |
13 | 13 | class NoRecordDeletionException extends Exception |
14 | 14 | { |
15 | - public static function checkNoRecordUpdateException($message) |
|
16 | - { |
|
17 | - return new static($message); |
|
18 | - } |
|
15 | + public static function checkNoRecordUpdateException($message) |
|
16 | + { |
|
17 | + return new static($message); |
|
18 | + } |
|
19 | 19 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | |
22 | 22 | public function __construct() |
23 | 23 | { |
24 | - $this->loadEnv(); // load the environment variables |
|
25 | - $this->databaseName = getenv('databaseName'); |
|
24 | + $this->loadEnv(); // load the environment variables |
|
25 | + $this->databaseName = getenv('databaseName'); |
|
26 | 26 | $this->databaseHost = getenv('databaseHost'); |
27 | 27 | $this->databaseDriver = getenv('databaseDriver'); |
28 | 28 | $this->databaseUsername = getenv('databaseUsername'); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | if (!getenv("APP_ENV")) { |
80 | 80 | $dotenv = new Dotenv(__DIR__.'/../../'); |
81 | - $dotenv->load(); |
|
81 | + $dotenv->load(); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
@@ -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 | |
39 | 39 | return $e->getMessage(); |
40 | 40 | } |
@@ -53,20 +53,20 @@ discard block |
||
53 | 53 | { |
54 | 54 | case 'mysql': |
55 | 55 | // Set DSN |
56 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
56 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
57 | 57 | break; |
58 | 58 | case 'sqlite': |
59 | 59 | // Set DSN |
60 | - $dsn = 'sqlite:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
60 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
61 | 61 | break; |
62 | 62 | case 'pgsql': |
63 | 63 | |
64 | 64 | // Set DSN |
65 | - $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
65 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
66 | 66 | break; |
67 | 67 | default: |
68 | 68 | // Set DSN |
69 | - $dsn = 'mysql:host='.$this->databaseHost.';dbname='. $this->databaseName; |
|
69 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; |
|
70 | 70 | } |
71 | 71 | return $dsn; |
72 | 72 | } |