| @@ -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 | |
| @@ -38,7 +38,7 @@ discard block | ||
| 38 | 38 | |
| 39 | 39 |  			$sql = 'CREATE TABLE IF NOT EXISTS '.$tableName.'('; | 
| 40 | 40 | |
| 41 | - $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 ) )'; | |
| 41 | + $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 ) )'; | |
| 42 | 42 | |
| 43 | 43 | return $conn->exec($sql); | 
| 44 | 44 | |
| @@ -53,7 +53,7 @@ discard block | ||
| 53 | 53 | * @param $table | 
| 54 | 54 | * @return array | 
| 55 | 55 | */ | 
| 56 | -	public function getColumnNames($table, $conn = Null){ | |
| 56 | +	public function getColumnNames($table, $conn = Null) { | |
| 57 | 57 | |
| 58 | 58 | $tableFields = []; | 
| 59 | 59 | |
| @@ -72,7 +72,7 @@ discard block | ||
| 72 | 72 | |
| 73 | 73 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); | 
| 74 | 74 | |
| 75 | -			foreach($results as $result) { | |
| 75 | +			foreach ($results as $result) { | |
| 76 | 76 | array_push($tableFields, $result['Field']); | 
| 77 | 77 | } | 
| 78 | 78 | |
| @@ -80,7 +80,7 @@ discard block | ||
| 80 | 80 | |
| 81 | 81 |  		} catch (PDOException $e) { | 
| 82 | 82 | |
| 83 | -			trigger_error('Could not connect to MySQL database. ' . $e->getMessage() , E_USER_ERROR); | |
| 83 | +			trigger_error('Could not connect to MySQL database. '.$e->getMessage(), E_USER_ERROR); | |
| 84 | 84 | } | 
| 85 | 85 | } | 
| 86 | 86 | |
| @@ -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) { | 
| @@ -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) | 
| 27 | 28 |  	{ | 
| @@ -37,6 +38,7 @@ discard block | ||
| 37 | 38 | /** | 
| 38 | 39 | * This method create a record and store it in a table row | 
| 39 | 40 | * @params associative array, string tablename | 
| 41 | + * @param string|false $tableName | |
| 40 | 42 | * @return boolean true or false | 
| 41 | 43 | */ | 
| 42 | 44 | public function create($associative1DArray, $tableName, $dbConn = Null) | 
| @@ -80,6 +82,10 @@ discard block | ||
| 80 | 82 | * @params: $updateParams, $tableName, $associative1DArray | 
| 81 | 83 | * @return boolean true or false | 
| 82 | 84 | */ | 
| 85 | + | |
| 86 | + /** | |
| 87 | + * @param string|false $tableName | |
| 88 | + */ | |
| 83 | 89 | public function update(array $updateParams, $tableName, $associative1DArray, $dbConn = Null) | 
| 84 | 90 |  	{ | 
| 85 | 91 | $counter = 0; | 
| @@ -124,6 +130,7 @@ discard block | ||
| 124 | 130 | /** | 
| 125 | 131 | * This method retrieves record from a table | 
| 126 | 132 | * @params int id, string tableName | 
| 133 | + * @param string|false $tableName | |
| 127 | 134 | * @return array | 
| 128 | 135 | */ | 
| 129 | 136 | public static function read($id, $tableName, $dbConn = Null) | 
| @@ -162,6 +169,7 @@ discard block | ||
| 162 | 169 | /** | 
| 163 | 170 | * This method deletes a record from a table row | 
| 164 | 171 | * @params int id, string tableName | 
| 172 | + * @param string|false $tableName | |
| 165 | 173 | * @return boolean true or false | 
| 166 | 174 | */ | 
| 167 | 175 | public static function delete($id, $tableName, $dbConn = Null) | 
| @@ -204,7 +212,7 @@ discard block | ||
| 204 | 212 | |
| 205 | 213 | /** | 
| 206 | 214 | * This method returns sql query | 
| 207 | - * @param $sql | |
| 215 | + * @param string $sql | |
| 208 | 216 | * @return string | 
| 209 | 217 | */ | 
| 210 | 218 | private function prepareUpdateQuery($sql) | 
| @@ -42,11 +42,11 @@ discard block | ||
| 42 | 42 | */ | 
| 43 | 43 | public function create($associative1DArray, $tableName, $dbConn = Null) | 
| 44 | 44 |  	{ | 
| 45 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray); | |
| 45 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray); | |
| 46 | 46 | |
| 47 | 47 | if (count($unexpectedFields) > 0) | 
| 48 | 48 |  		{ | 
| 49 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); | |
| 49 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); | |
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | 52 | unset($this->tableFields[0]); | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 | |
| 58 | 58 | $insertQuery = 'INSERT INTO '.$tableName; | 
| 59 | 59 | |
| 60 | -		$TableValues = implode(',',array_keys($associative1DArray)); | |
| 60 | +		$TableValues = implode(',', array_keys($associative1DArray)); | |
| 61 | 61 | |
| 62 | 62 | |
| 63 | 63 | var_dump($associative1DArray); | 
| @@ -68,13 +68,13 @@ discard block | ||
| 68 | 68 | } | 
| 69 | 69 |  		$splittedTableValues = implode(',', $FormValues); | 
| 70 | 70 | |
| 71 | -		$insertQuery.= ' ('.$TableValues.')'; | |
| 71 | +		$insertQuery .= ' ('.$TableValues.')'; | |
| 72 | 72 | |
| 73 | -		$insertQuery.= ' VALUES ('.$splittedTableValues.')'; | |
| 73 | +		$insertQuery .= ' VALUES ('.$splittedTableValues.')'; | |
| 74 | 74 | |
| 75 | 75 | $executeQuery = $dbConn->exec($insertQuery); | 
| 76 | 76 | |
| 77 | - return $executeQuery ? : false; | |
| 77 | + return $executeQuery ?: false; | |
| 78 | 78 | } | 
| 79 | 79 | |
| 80 | 80 | /* | 
| @@ -95,15 +95,15 @@ discard block | ||
| 95 | 95 | |
| 96 | 96 | unset($associative1DArray['id']); | 
| 97 | 97 | |
| 98 | - $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray); | |
| 98 | + $unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray); | |
| 99 | 99 | |
| 100 | 100 |  		if (count($unexpectedFields) > 0) { | 
| 101 | 101 | |
| 102 | - throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field"); | |
| 102 | + throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field"); | |
| 103 | 103 | } | 
| 104 | 104 | |
| 105 | 105 | |
| 106 | - foreach($associative1DArray as $field => $value) | |
| 106 | + foreach ($associative1DArray as $field => $value) | |
| 107 | 107 |  		{ | 
| 108 | 108 | $sql .= "`$field` = '$value'".","; | 
| 109 | 109 | } | 
| @@ -119,7 +119,7 @@ discard block | ||
| 119 | 119 | |
| 120 | 120 | $boolResponse = $stmt->execute(); | 
| 121 | 121 | |
| 122 | - return $boolResponse ? : false; | |
| 122 | + return $boolResponse ?: false; | |
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | /** | 
| @@ -137,7 +137,7 @@ discard block | ||
| 137 | 137 | |
| 138 | 138 | } | 
| 139 | 139 | |
| 140 | - $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; | |
| 140 | + $sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName; | |
| 141 | 141 | |
| 142 | 142 |  		try { | 
| 143 | 143 | $stmt = $dbConn->prepare($sql); | 
| @@ -151,7 +151,7 @@ discard block | ||
| 151 | 151 | } | 
| 152 | 152 | $results = $stmt->fetchAll(PDO::FETCH_ASSOC); | 
| 153 | 153 | |
| 154 | -		foreach($results as $result) { | |
| 154 | +		foreach ($results as $result) { | |
| 155 | 155 | |
| 156 | 156 | array_push($tableData, $result); | 
| 157 | 157 | } | 
| @@ -177,7 +177,7 @@ discard block | ||
| 177 | 177 | |
| 178 | 178 | $boolResponse = $dbConn->exec($sql); | 
| 179 | 179 | |
| 180 | - return $boolResponse ? : false; | |
| 180 | + return $boolResponse ?: false; | |
| 181 | 181 | } | 
| 182 | 182 | |
| 183 | 183 | /** | 
| @@ -192,7 +192,7 @@ discard block | ||
| 192 | 192 | |
| 193 | 193 | foreach ($userSetterArray as $key => $val) | 
| 194 | 194 |  		{ | 
| 195 | -			if (!in_array($key,$tableColumn)) { | |
| 195 | +			if (!in_array($key, $tableColumn)) { | |
| 196 | 196 | |
| 197 | 197 | $unexpectedFields[] = $key; | 
| 198 | 198 | } | 
| @@ -208,11 +208,11 @@ discard block | ||
| 208 | 208 | */ | 
| 209 | 209 | private function prepareUpdateQuery($sql) | 
| 210 | 210 |  	{ | 
| 211 | -		$splittedQuery = explode(",",$sql); | |
| 211 | +		$splittedQuery = explode(",", $sql); | |
| 212 | 212 | |
| 213 | 213 | array_pop($splittedQuery); | 
| 214 | 214 | |
| 215 | -		$mergeData = implode(",",$splittedQuery); | |
| 215 | +		$mergeData = implode(",", $splittedQuery); | |
| 216 | 216 | |
| 217 | 217 | return $mergeData; | 
| 218 | 218 | } | 
| @@ -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 | |
| @@ -15,9 +15,9 @@ discard block | ||
| 15 | 15 | class DatabaseConnection extends \PDO | 
| 16 | 16 |  { | 
| 17 | 17 | private $databaseName; | 
| 18 | - private $databaseHost; | |
| 18 | + private $databaseHost; | |
| 19 | 19 | private $databaseDriver; | 
| 20 | - private $databaseUsername; | |
| 20 | + private $databaseUsername; | |
| 21 | 21 | private $databasePassword; | 
| 22 | 22 | private $databaseHandle; | 
| 23 | 23 | |
| @@ -104,7 +104,7 @@ discard block | ||
| 104 | 104 | |
| 105 | 105 | //$dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']); | 
| 106 | 106 | $dotenv = new Dotenv(__DIR__.'/../../'); | 
| 107 | - $dotenv->load(); | |
| 107 | + $dotenv->load(); | |
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | } | 
| @@ -24,11 +24,11 @@ discard block | ||
| 24 | 24 |  	{ | 
| 25 | 25 | self::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 | |
| @@ -40,7 +40,7 @@ discard block | ||
| 40 | 40 | ]; | 
| 41 | 41 | parent::__construct($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options); | 
| 42 | 42 | |
| 43 | -			} catch(PDOException $e) { | |
| 43 | +			} catch (PDOException $e) { | |
| 44 | 44 | |
| 45 | 45 | return $e->getMessage(); | 
| 46 | 46 | |
| @@ -62,21 +62,21 @@ discard block | ||
| 62 | 62 | case 'mysql': | 
| 63 | 63 | |
| 64 | 64 | // Set DSN | 
| 65 | - $dsn = 'mysql:host='. $this->databaseHost. ';dbname='. $this->databaseName; | |
| 65 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; | |
| 66 | 66 | break; | 
| 67 | 67 | case 'sqlite': | 
| 68 | 68 | |
| 69 | 69 | // Set DSN | 
| 70 | - $dsn = 'sqlite:host='. $this->databaseHost. ';dbname='. $this->databaseName; | |
| 70 | + $dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName; | |
| 71 | 71 | break; | 
| 72 | 72 | case 'pgsql': | 
| 73 | 73 | |
| 74 | 74 | // Set DSN | 
| 75 | - $dsn = 'pgsqlsql:host='. $this->databaseHost. ';dbname='. $this->databaseName; | |
| 75 | + $dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName; | |
| 76 | 76 | break; | 
| 77 | 77 | default: | 
| 78 | 78 | // Set DSN | 
| 79 | - $dsn = 'mysql:host='. $this->databaseHost. ';dbname='. $this->databaseName; | |
| 79 | + $dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName; | |
| 80 | 80 | } | 
| 81 | 81 | return $dsn; | 
| 82 | 82 | } | 
| @@ -17,7 +17,7 @@ | ||
| 17 | 17 | |
| 18 | 18 |  		$splittedArray = implode(",", $fieldsNotDefined); | 
| 19 | 19 | |
| 20 | - return new static ($splittedArray . " " . $message); | |
| 20 | + return new static ($splittedArray." ".$message); | |
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | 23 | } | 
| 24 | 24 | \ No newline at end of file |