@@ -21,6 +21,7 @@ discard block |
||
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * This is a constructor; a default method that will be called automatically during class instantiation |
| 24 | + * @param string|false $modelClassName |
|
| 24 | 25 | */ |
| 25 | 26 | public function __construct($modelClassName, $dbConn = Null) |
| 26 | 27 | { |
@@ -35,6 +36,7 @@ discard block |
||
| 35 | 36 | /** |
| 36 | 37 | * This method create a record and store it in a table row |
| 37 | 38 | * @params associative array, string tablename |
| 39 | + * @param string|false $tableName |
|
| 38 | 40 | * @return boolean true or false |
| 39 | 41 | */ |
| 40 | 42 | public function create($associative1DArray, $tableName, $dbConn = Null) |
@@ -69,6 +71,7 @@ discard block |
||
| 69 | 71 | /** |
| 70 | 72 | * This method updates any table by supplying 3 parameter |
| 71 | 73 | * @params: $updateParams, $tableName, $associative1DArray |
| 74 | + * @param string|false $tableName |
|
| 72 | 75 | * @return boolean true or false |
| 73 | 76 | */ |
| 74 | 77 | public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) |
@@ -101,6 +104,7 @@ discard block |
||
| 101 | 104 | /** |
| 102 | 105 | * This method retrieves record from a table |
| 103 | 106 | * @params int id, string tableName |
| 107 | + * @param string|false $tableName |
|
| 104 | 108 | * @return array |
| 105 | 109 | */ |
| 106 | 110 | public static function read($id, $tableName, $dbConn = Null) |
@@ -131,6 +135,7 @@ discard block |
||
| 131 | 135 | /** |
| 132 | 136 | * This method deletes a record from a table row |
| 133 | 137 | * @params int id, string tableName |
| 138 | + * @param string|false $tableName |
|
| 134 | 139 | * @return boolean true or false |
| 135 | 140 | */ |
| 136 | 141 | public static function delete($id, $tableName, $dbConn = Null) |
@@ -163,7 +168,7 @@ discard block |
||
| 163 | 168 | |
| 164 | 169 | /** |
| 165 | 170 | * This method returns sql query |
| 166 | - * @param $sql |
|
| 171 | + * @param string $sql |
|
| 167 | 172 | * @return string |
| 168 | 173 | */ |
| 169 | 174 | public function prepareUpdateQuery($sql) |
@@ -204,6 +209,7 @@ discard block |
||
| 204 | 209 | * This method returns column fields of a particular table |
| 205 | 210 | * @param $table |
| 206 | 211 | * @param $conn |
| 212 | + * @param DatabaseConnection $dbConn |
|
| 207 | 213 | * @return array |
| 208 | 214 | */ |
| 209 | 215 | public function getColumnNames($table, $dbConn = Null) { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($tableFields, $associative1DArray); |
| 52 | 52 | |
| 53 | 53 | if (count($unexpectedFields) > 0) { |
| 54 | - throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields,"needs to be created as a table field"); |
|
| 54 | + throw TableFieldUndefinedException::reportUnknownTableField($unexpectedFields, "needs to be created as a table field"); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | unset($associative1DArray[0]); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | { |
| 77 | 77 | $insertQuery = 'INSERT INTO '.$tableName; |
| 78 | 78 | |
| 79 | - $TableValues = implode(',',array_keys($associative1DArray)); |
|
| 79 | + $TableValues = implode(',', array_keys($associative1DArray)); |
|
| 80 | 80 | |
| 81 | 81 | foreach ($associative1DArray as $field => $value) { |
| 82 | 82 | $FormValues[] = "'".trim(addslashes($value))."'"; |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | $splittedTableValues = implode(',', $FormValues); |
| 86 | 86 | |
| 87 | - $insertQuery.= ' ('.$TableValues.')'; |
|
| 88 | - $insertQuery.= ' VALUES ('.$splittedTableValues.')'; |
|
| 87 | + $insertQuery .= ' ('.$TableValues.')'; |
|
| 88 | + $insertQuery .= ' VALUES ('.$splittedTableValues.')'; |
|
| 89 | 89 | |
| 90 | 90 | $executeQuery = $dbConn->exec($insertQuery); |
| 91 | 91 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $unexpectedFields = []; |
| 217 | 217 | |
| 218 | 218 | foreach ($userSetterArray as $key => $val) { |
| 219 | - if (!in_array($key,$tableColumn)) { |
|
| 219 | + if (!in_array($key, $tableColumn)) { |
|
| 220 | 220 | $unexpectedFields[] = $key; |
| 221 | 221 | } |
| 222 | 222 | } |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | public function prepareUpdateQuery($sql) |
| 234 | 234 | { |
| 235 | - $splittedQuery = explode(",",$sql); |
|
| 235 | + $splittedQuery = explode(",", $sql); |
|
| 236 | 236 | |
| 237 | 237 | array_pop($splittedQuery); |
| 238 | 238 | |
| 239 | - $mergeData = implode(",",$splittedQuery); |
|
| 239 | + $mergeData = implode(",", $splittedQuery); |
|
| 240 | 240 | |
| 241 | 241 | return $mergeData; |
| 242 | 242 | |
@@ -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) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | /** |
| 118 | 118 | * This method find a record by id |
| 119 | 119 | * @params int id |
| 120 | - * @return Object |
|
| 120 | + * @return BaseModel |
|
| 121 | 121 | * @throws NoArgumentPassedToFunctionException |
| 122 | 122 | */ |
| 123 | 123 | public static function find($id) |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | /** |
| 169 | 169 | * This method return the current class name |
| 170 | 170 | * $params void |
| 171 | - * @return classname |
|
| 171 | + * @return string|false |
|
| 172 | 172 | */ |
| 173 | 173 | public static function getClassName() |
| 174 | 174 | { |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $this->loadEnv(); // load the environment variables |
| 26 | 26 | |
| 27 | - $this->databaseName = getenv('databaseName'); |
|
| 28 | - $this->databaseHost = getenv('databaseHost'); |
|
| 29 | - $this->databaseDriver = getenv('databaseDriver'); |
|
| 30 | - $this->databaseUsername = getenv('databaseUsername'); |
|
| 31 | - $this->databasePassword = getenv('databasePassword'); |
|
| 27 | + $this->databaseName = getenv('databaseName'); |
|
| 28 | + $this->databaseHost = getenv('databaseHost'); |
|
| 29 | + $this->databaseDriver = getenv('databaseDriver'); |
|
| 30 | + $this->databaseUsername = getenv('databaseUsername'); |
|
| 31 | + $this->databasePassword = getenv('databasePassword'); |
|
| 32 | 32 | |
| 33 | 33 | try { |
| 34 | 34 | $options = [ |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); |
| 40 | 40 | |
| 41 | - } catch(PDOException $e) { |
|
| 41 | + } catch (PDOException $e) { |
|
| 42 | 42 | return $e->getMessage(); |
| 43 | 43 | |
| 44 | 44 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function loadEnv() |
| 80 | 80 | { |
| 81 | - if (! getenv("APP_ENV")) { |
|
| 81 | + if (!getenv("APP_ENV")) { |
|
| 82 | 82 | $dotenv = new Dotenv(__DIR__.'/../../'); |
| 83 | 83 | $dotenv->load(); |
| 84 | 84 | } |
@@ -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 | |
@@ -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 | |