@@ -1,11 +1,11 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Defining Interface for class DatabaseQueryInterface. |
|
4 | - * |
|
5 | - * @package Ibonly\PotatoORM\DatabaseQueryInterface |
|
6 | - * @author Ibraheem ADENIYI <[email protected]> |
|
7 | - * @license MIT <https://opensource.org/licenses/MIT> |
|
8 | - */ |
|
3 | + * Defining Interface for class DatabaseQueryInterface. |
|
4 | + * |
|
5 | + * @package Ibonly\PotatoORM\DatabaseQueryInterface |
|
6 | + * @author Ibraheem ADENIYI <[email protected]> |
|
7 | + * @license MIT <https://opensource.org/licenses/MIT> |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | namespace Ibonly\PotatoORM; |
11 | 11 |
@@ -62,8 +62,8 @@ discard block |
||
62 | 62 | /** |
63 | 63 | *@method bool ValidateExtension() returns whether the extension of file to be uploaded |
64 | 64 | * is allowable or not. |
65 | - *@return true the extension is valid. |
|
66 | - *@return false the extension is invalid. |
|
65 | + *@return boolean the extension is valid. |
|
66 | + *@return boolean the extension is invalid. |
|
67 | 67 | */ |
68 | 68 | public function ValidateExtension() |
69 | 69 | { |
@@ -95,8 +95,8 @@ discard block |
||
95 | 95 | |
96 | 96 | /** |
97 | 97 | *@method bool ValidateSize() returns whether the file size is acceptable. |
98 | - *@return true the size is smaller than the alloted value. |
|
99 | - *@return false the size is larger than the alloted value. |
|
98 | + *@return boolean the size is smaller than the alloted value. |
|
99 | + *@return boolean the size is larger than the alloted value. |
|
100 | 100 | */ |
101 | 101 | public function ValidateSize() |
102 | 102 | { |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | |
121 | 121 | /** |
122 | 122 | *@method bool ValidateExistance() determins whether the file already exists. If so, rename $FileName. |
123 | - *@return true can never be returned as all file names must be unique. |
|
124 | - *@return false the file name does not exist. |
|
123 | + *@return null|false can never be returned as all file names must be unique. |
|
124 | + *@return null|false the file name does not exist. |
|
125 | 125 | */ |
126 | 126 | public function ValidateExistance() |
127 | 127 | { |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | |
143 | 143 | /** |
144 | 144 | *@method bool ValidateDirectory() |
145 | - *@return true the UploadDirectory exists, writable, and has a traling slash. |
|
146 | - *@return false the directory was never set, does not exist, or is not writable. |
|
145 | + *@return null|boolean the UploadDirectory exists, writable, and has a traling slash. |
|
146 | + *@return null|boolean the directory was never set, does not exist, or is not writable. |
|
147 | 147 | */ |
148 | 148 | public function ValidateDirectory() |
149 | 149 | { |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | |
178 | 178 | /** |
179 | 179 | *@method bool ValidateImage() |
180 | - *@return true the image is smaller than the alloted dimensions. |
|
181 | - *@return false the width and/or height is larger then the alloted dimensions. |
|
180 | + *@return boolean the image is smaller than the alloted dimensions. |
|
181 | + *@return boolean the width and/or height is larger then the alloted dimensions. |
|
182 | 182 | */ |
183 | 183 | public function ValidateImage() { |
184 | 184 | $MaximumWidth = $this->MaximumWidth; |
@@ -206,8 +206,8 @@ discard block |
||
206 | 206 | |
207 | 207 | /** |
208 | 208 | *@method bool UploadFile() uploads the file to the server after passing all the validations. |
209 | - *@return true the file was uploaded. |
|
210 | - *@return false the upload failed. |
|
209 | + *@return null|boolean the file was uploaded. |
|
210 | + *@return null|boolean the upload failed. |
|
211 | 211 | */ |
212 | 212 | public function uploadFile() |
213 | 213 | { |
@@ -251,11 +251,18 @@ discard block |
||
251 | 251 | |
252 | 252 | #Accessors and Mutators beyond this point. |
253 | 253 | #Siginificant documentation is not needed. |
254 | + |
|
255 | + /** |
|
256 | + * @param string $argv |
|
257 | + */ |
|
254 | 258 | public function SetFileName($argv) |
255 | 259 | { |
256 | 260 | $this->FileName = $argv; |
257 | 261 | } |
258 | 262 | |
263 | + /** |
|
264 | + * @param string $argv |
|
265 | + */ |
|
259 | 266 | public function SetUploadDirectory($argv) |
260 | 267 | { |
261 | 268 | $this->UploadDirectory = $argv; |
@@ -310,6 +317,9 @@ discard block |
||
310 | 317 | return $this->UploadDirectory; |
311 | 318 | } |
312 | 319 | |
320 | + /** |
|
321 | + * @return string |
|
322 | + */ |
|
313 | 323 | public function GetTempName() |
314 | 324 | { |
315 | 325 | return $this->TempFileName; |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | $Extension = strtolower($FileParts['extension']); |
74 | 74 | $ValidExtensions = $this->ValidExtensions; |
75 | 75 | |
76 | - if (!$FileName) { |
|
76 | + if ( ! $FileName) { |
|
77 | 77 | $this->SetMessage("ERROR: File name is empty."); |
78 | 78 | return false; |
79 | 79 | } |
80 | 80 | |
81 | - if (!$ValidExtensions) { |
|
81 | + if ( ! $ValidExtensions) { |
|
82 | 82 | $this->SetMessage("WARNING: All extensions are valid."); |
83 | 83 | return true; |
84 | 84 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $TempFileName = $this->GetTempName(); |
105 | 105 | $TempFileSize = filesize($TempFileName); |
106 | 106 | |
107 | - if($MaximumFileSize == "") { |
|
107 | + if ($MaximumFileSize == "") { |
|
108 | 108 | $this->SetMessage("WARNING: There is no size restriction."); |
109 | 109 | return true; |
110 | 110 | } |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | { |
128 | 128 | $FileName = $this->FileName; |
129 | 129 | $UploadDirectory = $this->UploadDirectory; |
130 | - $File = $UploadDirectory . $FileName; |
|
130 | + $File = $UploadDirectory.$FileName; |
|
131 | 131 | |
132 | 132 | if (file_exists($File)) { |
133 | 133 | $this->SetMessage("Message: The file '$FileName' already exist."); |
134 | - $UniqueName = rand() . $FileName; |
|
134 | + $UniqueName = rand().$FileName; |
|
135 | 135 | $this->SetFileName($UniqueName); |
136 | 136 | $this->ValidateExistance(); |
137 | 137 | } else { |
@@ -149,24 +149,24 @@ discard block |
||
149 | 149 | { |
150 | 150 | $UploadDirectory = $this->UploadDirectory; |
151 | 151 | |
152 | - if (!$UploadDirectory) { |
|
152 | + if ( ! $UploadDirectory) { |
|
153 | 153 | $this->SetMessage("ERROR: The directory variable is empty."); |
154 | 154 | return false; |
155 | 155 | } |
156 | 156 | |
157 | - if (!is_dir($UploadDirectory)) { |
|
157 | + if ( ! is_dir($UploadDirectory)) { |
|
158 | 158 | $this->SetMessage("ERROR: The directory '$UploadDirectory' does not exist."); |
159 | 159 | return false; |
160 | 160 | } |
161 | 161 | |
162 | - if (!is_writable($UploadDirectory)) { |
|
162 | + if ( ! is_writable($UploadDirectory)) { |
|
163 | 163 | $this->SetMessage("ERROR: The directory '$UploadDirectory' does not writable."); |
164 | 164 | return false; |
165 | 165 | } |
166 | 166 | |
167 | 167 | if (substr($UploadDirectory, -1) != "/") { |
168 | 168 | $this->SetMessage("ERROR: The traling slash does not exist."); |
169 | - $NewDirectory = $UploadDirectory . "/"; |
|
169 | + $NewDirectory = $UploadDirectory."/"; |
|
170 | 170 | $this->SetUploadDirectory($NewDirectory); |
171 | 171 | $this->ValidateDirectory(); |
172 | 172 | } else { |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | $MaximumHeight = $this->MaximumHeight; |
186 | 186 | $TempFileName = $this->TempFileName; |
187 | 187 | |
188 | - if($Size = @getimagesize($TempFileName)) { |
|
189 | - $Width = $Size[0]; //$Width is the width in pixels of the image uploaded to the server. |
|
190 | - $Height = $Size[1]; //$Height is the height in pixels of the image uploaded to the server. |
|
188 | + if ($Size = @getimagesize($TempFileName)) { |
|
189 | + $Width = $Size[0]; //$Width is the width in pixels of the image uploaded to the server. |
|
190 | + $Height = $Size[1]; //$Height is the height in pixels of the image uploaded to the server. |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | if ($Width > $MaximumWidth) { |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | public function uploadFile() |
213 | 213 | { |
214 | 214 | |
215 | - if (!$this->ValidateExtension()) { |
|
215 | + if ( ! $this->ValidateExtension()) { |
|
216 | 216 | die($this->GetMessage()); |
217 | 217 | } |
218 | 218 | |
219 | - else if (!$this->ValidateSize()) { |
|
219 | + else if ( ! $this->ValidateSize()) { |
|
220 | 220 | die($this->GetMessage()); |
221 | 221 | } |
222 | 222 | |
@@ -224,11 +224,11 @@ discard block |
||
224 | 224 | die($this->GetMessage()); |
225 | 225 | } |
226 | 226 | |
227 | - else if (!$this->ValidateDirectory()) { |
|
227 | + else if ( ! $this->ValidateDirectory()) { |
|
228 | 228 | die($this->GetMessage()); |
229 | 229 | } |
230 | 230 | |
231 | - else if ($this->IsImage && !$this->ValidateImage()) { |
|
231 | + else if ($this->IsImage && ! $this->ValidateImage()) { |
|
232 | 232 | die($this->GetMessage()); |
233 | 233 | } |
234 | 234 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $UploadDirectory = $this->UploadDirectory; |
240 | 240 | |
241 | 241 | if (is_uploaded_file($TempFileName)) { |
242 | - move_uploaded_file($TempFileName, $UploadDirectory . $FileName); |
|
242 | + move_uploaded_file($TempFileName, $UploadDirectory.$FileName); |
|
243 | 243 | return true; |
244 | 244 | } else { |
245 | 245 | return false; |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | |
323 | 323 | public function GetMessage() |
324 | 324 | { |
325 | - if (!isset($this->Message)) { |
|
325 | + if ( ! isset($this->Message)) { |
|
326 | 326 | $this->SetMessage("No Message"); |
327 | 327 | } |
328 | 328 |
@@ -214,25 +214,15 @@ |
||
214 | 214 | |
215 | 215 | if (!$this->ValidateExtension()) { |
216 | 216 | die($this->GetMessage()); |
217 | - } |
|
218 | - |
|
219 | - else if (!$this->ValidateSize()) { |
|
217 | + } else if (!$this->ValidateSize()) { |
|
220 | 218 | die($this->GetMessage()); |
221 | - } |
|
222 | - |
|
223 | - else if ($this->ValidateExistance()) { |
|
219 | + } else if ($this->ValidateExistance()) { |
|
224 | 220 | die($this->GetMessage()); |
225 | - } |
|
226 | - |
|
227 | - else if (!$this->ValidateDirectory()) { |
|
221 | + } else if (!$this->ValidateDirectory()) { |
|
228 | 222 | die($this->GetMessage()); |
229 | - } |
|
230 | - |
|
231 | - else if ($this->IsImage && !$this->ValidateImage()) { |
|
223 | + } else if ($this->IsImage && !$this->ValidateImage()) { |
|
232 | 224 | die($this->GetMessage()); |
233 | - } |
|
234 | - |
|
235 | - else { |
|
225 | + } else { |
|
236 | 226 | |
237 | 227 | $FileName = $this->FileName; |
238 | 228 | $TempFileName = $this->TempFileName; |
@@ -1,17 +1,17 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Defining Interface for class GetData. |
|
4 | - * |
|
5 | - * @package Ibonly\PotatoORM\ModelInterface |
|
6 | - * @author Ibraheem ADENIYI <[email protected]> |
|
7 | - * @license MIT <https://opensource.org/licenses/MIT> |
|
8 | - */ |
|
3 | + * Defining Interface for class GetData. |
|
4 | + * |
|
5 | + * @package Ibonly\PotatoORM\ModelInterface |
|
6 | + * @author Ibraheem ADENIYI <[email protected]> |
|
7 | + * @license MIT <https://opensource.org/licenses/MIT> |
|
8 | + */ |
|
9 | 9 | |
10 | 10 | namespace Ibonly\PotatoORM; |
11 | 11 | |
12 | 12 | interface GetDataInterface |
13 | 13 | { |
14 | - public function all(); |
|
14 | + public function all(); |
|
15 | 15 | |
16 | 16 | public function allDESC($limit); |
17 | 17 | |
@@ -23,5 +23,5 @@ discard block |
||
23 | 23 | |
24 | 24 | public function first(); |
25 | 25 | |
26 | - public function getCount(); |
|
26 | + public function getCount(); |
|
27 | 27 | } |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | */ |
50 | 50 | protected static function checkConnection($con) |
51 | 51 | { |
52 | - if( $con === null ) |
|
52 | + if ($con === null) |
|
53 | 53 | { |
54 | 54 | $con = self::connect(); |
55 | 55 | } |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return bool |
66 | 66 | */ |
67 | - public function checkTableExist($table, $con=NULL) |
|
67 | + public function checkTableExist($table, $con = NULL) |
|
68 | 68 | { |
69 | 69 | $connection = $this->checkConnection($con); |
70 | 70 | $query = $connection->query("SELECT 1 FROM {$table} LIMIT 1"); |
71 | - if( $query !== false ) |
|
71 | + if ($query !== false) |
|
72 | 72 | { |
73 | 73 | return true; |
74 | 74 | } |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return string |
84 | 84 | */ |
85 | - public static function checkTableName($tableName, $con=NULL) |
|
85 | + public static function checkTableName($tableName, $con = NULL) |
|
86 | 86 | { |
87 | 87 | $connection = self::checkConnection($con); |
88 | 88 | |
89 | 89 | $query = $connection->query("SELECT 1 FROM {$tableName} LIMIT 1"); |
90 | - if( $query !== false ) |
|
90 | + if ($query !== false) |
|
91 | 91 | { |
92 | 92 | return $tableName; |
93 | 93 | } |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return string |
105 | 105 | */ |
106 | - protected static function checkColumn($tableName, $columnName, $con=NULL) |
|
106 | + protected static function checkColumn($tableName, $columnName, $con = NULL) |
|
107 | 107 | { |
108 | 108 | $connection = self::checkConnection($con); |
109 | 109 | |
110 | 110 | $result = $connection->prepare("SELECT {$columnName} FROM {$tableName}"); |
111 | 111 | $result->execute(); |
112 | - if ( ! $result->columnCount() ) |
|
112 | + if ( ! $result->columnCount()) |
|
113 | 113 | { |
114 | 114 | throw new ColumnNotExistExeption(); |
115 | 115 | } |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | $columnNames = self::getColumns($getClassVars); |
153 | 153 | $arraySize = count($columnNames); |
154 | 154 | |
155 | - foreach ( $columnNames as $key => $value ) |
|
155 | + foreach ($columnNames as $key => $value) |
|
156 | 156 | { |
157 | 157 | $counter++; |
158 | 158 | $insertQuery .= self::sanitize($key); |
159 | - if( $arraySize > $counter ) |
|
159 | + if ($arraySize > $counter) |
|
160 | 160 | $insertQuery .= ", "; |
161 | 161 | } |
162 | 162 | |
@@ -177,11 +177,11 @@ discard block |
||
177 | 177 | $columnNames = self::getColumns($getClassVars); |
178 | 178 | $arraySize = count($columnNames); |
179 | 179 | |
180 | - foreach ( $columnNames as $key => $value ) |
|
180 | + foreach ($columnNames as $key => $value) |
|
181 | 181 | { |
182 | 182 | $counter++; |
183 | - $insertQuery .= "'".self::sanitize($value) ."'"; |
|
184 | - if( $arraySize > $counter ) |
|
183 | + $insertQuery .= "'".self::sanitize($value)."'"; |
|
184 | + if ($arraySize > $counter) |
|
185 | 185 | $insertQuery .= ", "; |
186 | 186 | } |
187 | 187 | return $insertQuery; |
@@ -200,12 +200,12 @@ discard block |
||
200 | 200 | $updateQuery = ""; |
201 | 201 | $arraySize = count($data); |
202 | 202 | |
203 | - foreach ( $data as $key => $value ) |
|
203 | + foreach ($data as $key => $value) |
|
204 | 204 | { |
205 | 205 | $counter++; |
206 | 206 | $columnName = self::checkColumn($tableName, self::sanitize($key)); |
207 | - $updateQuery .= $columnName ." = '".self::sanitize($value)."'"; |
|
208 | - if ( $arraySize > $counter ) |
|
207 | + $updateQuery .= $columnName." = '".self::sanitize($value)."'"; |
|
208 | + if ($arraySize > $counter) |
|
209 | 209 | { |
210 | 210 | $updateQuery .= ", "; |
211 | 211 | } |
@@ -234,14 +234,14 @@ discard block |
||
234 | 234 | $counter = 0; |
235 | 235 | $arraySize = count($data); |
236 | 236 | |
237 | - foreach ( $data as $key => $value ) |
|
237 | + foreach ($data as $key => $value) |
|
238 | 238 | { |
239 | 239 | $counter++; |
240 | 240 | $columnName = self::checkColumn($tableName, self::sanitize($key)); |
241 | - $where .= $columnName ." = '".self::sanitize($value)."'"; |
|
242 | - if ( $arraySize > $counter ) |
|
241 | + $where .= $columnName." = '".self::sanitize($value)."'"; |
|
242 | + if ($arraySize > $counter) |
|
243 | 243 | { |
244 | - $where .= " " . $condition . " "; |
|
244 | + $where .= " ".$condition." "; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
@@ -259,14 +259,14 @@ discard block |
||
259 | 259 | try |
260 | 260 | { |
261 | 261 | $arraySize = count($data); |
262 | - if( $arraySize > 1 && $condition == NULL) |
|
262 | + if ($arraySize > 1 && $condition == NULL) |
|
263 | 263 | { |
264 | 264 | $query = "Please Supply the condition"; |
265 | 265 | } |
266 | 266 | else |
267 | 267 | { |
268 | 268 | $columnName = self::whereAndClause($tableName, $data, $condition); |
269 | - $query = "SELECT $fields FROM $tableName WHERE $columnName"; |
|
269 | + $query = "SELECT $fields FROM $tableName WHERE $columnName"; |
|
270 | 270 | } |
271 | 271 | } catch (PDOException $e) { |
272 | 272 | $query = $e->getMessage(); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function insertQuery($tableName) |
284 | 284 | { |
285 | - $data = ( array )$this; |
|
285 | + $data = (array)$this; |
|
286 | 286 | array_shift($data); |
287 | 287 | |
288 | 288 | $columnNames = self::buildColumn($data); |
@@ -298,11 +298,11 @@ discard block |
||
298 | 298 | */ |
299 | 299 | public function updateQuery($tableName) |
300 | 300 | { |
301 | - $data = ( array ) $this; |
|
301 | + $data = (array)$this; |
|
302 | 302 | $data = array_slice($data, 2); |
303 | 303 | |
304 | 304 | $values = self::buildClause($tableName, $data); |
305 | - $updateQuery = "UPDATE $tableName SET {$values} WHERE id = ". self::sanitize($this->id); |
|
305 | + $updateQuery = "UPDATE $tableName SET {$values} WHERE id = ".self::sanitize($this->id); |
|
306 | 306 | |
307 | 307 | return $updateQuery; |
308 | 308 | } |
@@ -25,13 +25,13 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return array |
27 | 27 | */ |
28 | - public function field($type, $fieldName, $length=NULL) |
|
28 | + public function field($type, $fieldName, $length = NULL) |
|
29 | 29 | { |
30 | - if($length === null){ |
|
31 | - $this->fieldDescription[] = $type ." ".$fieldName; |
|
32 | - }else |
|
30 | + if ($length === null) { |
|
31 | + $this->fieldDescription[] = $type." ".$fieldName; |
|
32 | + } else |
|
33 | 33 | { |
34 | - $this->fieldDescription[] = $type ." ".$fieldName." ".$length; |
|
34 | + $this->fieldDescription[] = $type." ".$fieldName." ".$length; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | } |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | $fields = explode(" ", $fieldName); |
52 | 52 | |
53 | 53 | $constrain = $fields[0]; |
54 | - if(count($fields) == 2) |
|
54 | + if (count($fields) == 2) |
|
55 | 55 | { |
56 | - $query .= $this->$constrain($fields[1], 20) .", ".PHP_EOL; |
|
57 | - }else |
|
56 | + $query .= $this->$constrain($fields[1], 20).", ".PHP_EOL; |
|
57 | + } else |
|
58 | 58 | { |
59 | - $query .= $this->$constrain($fields[1], $fields[2]) .", ".PHP_EOL; |
|
59 | + $query .= $this->$constrain($fields[1], $fields[2]).", ".PHP_EOL; |
|
60 | 60 | } |
61 | 61 | }; |
62 | 62 | array_walk($this->fieldDescription, $callback); |
@@ -90,11 +90,11 @@ discard block |
||
90 | 90 | { |
91 | 91 | $sqlQuery = self::sanitizeQuery($tablename); |
92 | 92 | $query = $connection->prepare($sqlQuery); |
93 | - if($query->execute()) |
|
93 | + if ($query->execute()) |
|
94 | 94 | { |
95 | 95 | return true; |
96 | 96 | } |
97 | - }catch(PDOException $e){ |
|
97 | + } catch (PDOException $e) { |
|
98 | 98 | return $e->getMessage(); |
99 | 99 | } |
100 | 100 | } |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function strings($value, $length) |
118 | 118 | { |
119 | - return $value ." varchar (".$length.") NOT NULL"; |
|
119 | + return $value." varchar (".$length.") NOT NULL"; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -202,6 +202,6 @@ discard block |
||
202 | 202 | $apend = 'timestamp'; |
203 | 203 | break; |
204 | 204 | } |
205 | - return $value . " " . $apend . " NOT NULL"; |
|
205 | + return $value." ".$apend." NOT NULL"; |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | \ No newline at end of file |