Test Failed
Push — database ( 5562a7...303e3a )
by Temitope
03:07 queued 43s
created
src/Database/DatabaseHandler.php 3 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -21,6 +21,7 @@  discard block
 block discarded – undo
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)
26 27
 	{
@@ -36,6 +37,7 @@  discard block
 block discarded – undo
36 37
 	/**
37 38
 	 * This method create a record and store it in a table row
38 39
 	 * @params associative array, string tablename
40
+	 * @param string|false $tableName
39 41
 	 * @return boolean true or false
40 42
 	 */
41 43
 	public function create($associative1DArray, $tableName, $dbConn = Null)
@@ -80,6 +82,10 @@  discard block
 block discarded – undo
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)
84 90
 	{
85 91
 		$counter = 0;
@@ -122,6 +128,7 @@  discard block
 block discarded – undo
122 128
 	/**
123 129
 	 * This method retrieves record from a table
124 130
 	 * @params int id, string tableName
131
+	 * @param string|false $tableName
125 132
 	 * @return array
126 133
 	 */
127 134
 	public static function read($id, $tableName)
@@ -156,6 +163,7 @@  discard block
 block discarded – undo
156 163
 	/**
157 164
 	 * This method deletes a record  from a table row
158 165
 	 * @params int id, string tableName
166
+	 * @param string|false $tableName
159 167
 	 * @return boolean true or false
160 168
 	 */
161 169
 	public static function delete($id,$tableName,$dbConn = "Null")
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 	private
18 18
 		$tableFields,
19 19
 		$dbHelperInstance,
20
-        $dbConnection;
20
+		$dbConnection;
21 21
 
22 22
 	/**
23 23
 	 * This is a constructor; a default method  that will be called automatically during class instantiation
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 use Laztopaz\potatoORM\DatabaseHelper;
13 13
 use Laztopaz\potatoORM\TableFieldUndefinedException;
14 14
 
15
-class DatabaseHandler  {
15
+class DatabaseHandler {
16 16
 
17 17
 	private
18 18
 		$tableFields,
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
 	 */
41 41
 	public function create($associative1DArray, $tableName, $dbConn = Null)
42 42
 	{
43
-		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray);
43
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray);
44 44
 
45 45
 		if (count($unexpectedFields) > 0)
46 46
 		{
47
-			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field");
47
+			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
48 48
 		}
49 49
 
50 50
 		unset($this->tableFields[0]);
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
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
 		foreach ($associative1DArray as $field => $value) {
63 63
 
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
 		}
66 66
 		$splittedTableValues = implode(',', $FormValues);
67 67
 
68
-		$insertQuery.= ' ('.$TableValues.')';
68
+		$insertQuery .= ' ('.$TableValues.')';
69 69
 
70
-		$insertQuery.= ' VALUES ('.$splittedTableValues.')';
70
+		$insertQuery .= ' VALUES ('.$splittedTableValues.')';
71 71
 
72 72
 		$executeQuery = $dbConn->exec($insertQuery);
73 73
 
74
-		return $executeQuery ? : false;
74
+		return $executeQuery ?: false;
75 75
 
76 76
 	}
77 77
 
@@ -84,11 +84,11 @@  discard block
 block discarded – undo
84 84
 	{
85 85
 		$counter = 0;
86 86
 
87
-		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields,$associative1DArray);
87
+		$unexpectedFields = self::checkIfMagicSetterContainsIsSameAsClassModel($this->tableFields, $associative1DArray);
88 88
 
89 89
 		if (count($unexpectedFields) > 0)
90 90
 		{
91
-			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields,"needs to be created as table field");
91
+			throw TableFieldUndefinedException::fieldsNotDefinedException($unexpectedFields, "needs to be created as table field");
92 92
 		}
93 93
 
94 94
 		unset($this->tableFields[0]);
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 
100 100
 			if ($counter == 0) {
101 101
 
102
-				$sql = sprintf( $sql." %s = '%s' ", "`$field`" , get_magic_quotes_gpc() ? $value: addslashes($value)) or die(PDO::ERRMODE_EXCEPTION);
102
+				$sql = sprintf($sql." %s = '%s' ", "`$field`", get_magic_quotes_gpc() ? $value : addslashes($value)) or die(PDO::ERRMODE_EXCEPTION);
103 103
 
104 104
 				$counter++;
105 105
 
106 106
 			} else {
107 107
 
108
-				$sql = sprintf( $sql.", %s = '%s' ", "`$field`" ,get_magic_quotes_gpc() ? $value: addslashes($value)) or die(PDO::ERRMODE_EXCEPTION);
108
+				$sql = sprintf($sql.", %s = '%s' ", "`$field`", get_magic_quotes_gpc() ? $value : addslashes($value)) or die(PDO::ERRMODE_EXCEPTION);
109 109
 			}
110 110
 		} // end foreach
111 111
 		foreach ($updateParams as $key => $val) {
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
 		$boolResponse = $this->dbConnection->exec($sql);
117 117
 
118
-		return $boolResponse ? : false;
118
+		return $boolResponse ?: false;
119 119
 
120 120
 	}
121 121
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	{
129 129
 		$tableData = array();
130 130
 
131
-		$sql = $id  ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
131
+		$sql = $id ? 'SELECT * FROM '.$tableName.' WHERE id = '.$id : 'SELECT * FROM '.$tableName;
132 132
 
133 133
 		try {
134 134
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		}
147 147
 		$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
148 148
 
149
-		foreach($results as $result) {
149
+		foreach ($results as $result) {
150 150
 			array_push($tableData, $result);
151 151
 		}
152 152
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @params int id, string tableName
159 159
 	 * @return boolean true or false
160 160
 	 */
161
-	public static function delete($id,$tableName,$dbConn = "Null")
161
+	public static function delete($id, $tableName, $dbConn = "Null")
162 162
 	{
163 163
 
164 164
 		if (is_null($dbConn)) {
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
 		$boolResponse = $dbConn->exec($sql);
173 173
 
174
-		return $boolResponse ? : false;
174
+		return $boolResponse ?: false;
175 175
 	}
176 176
 
177 177
 	/**
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
 		foreach ($userSetterArray as $key => $val)
188 188
 		{
189
-			if (!in_array($key,$tableColumn)) {
189
+			if (!in_array($key, $tableColumn)) {
190 190
 
191 191
 				$unexpectedFields[] = $key;
192 192
 			}
Please login to merge, or discard this patch.
src/Model/BaseModel.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 	{
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,6 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 
21 21
 class BaseClass  implements InterfaceBaseClass
22 22
 {
23
-	protected $databaseModel;   // Private variable that contains instance of database
23
+	protected $databaseModel; // Private variable that contains instance of database
24 24
 
25
-	protected $tableName;       // Class variable holding class name pluralized
25
+	protected $tableName; // Class variable holding class name pluralized
26 26
 
27 27
 	protected $properties = []; // Properties will later contain key, value pairs from the magic setter, getter methods
28 28
 
29
-	use Inflector;              // Inject the inflector trait
29
+	use Inflector; // Inject the inflector trait
30 30
 
31 31
 	public function  __construct()
32 32
 	{
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @params property, key
54 54
 	 * @return array associative array properties
55 55
 	 */
56
-	public function  __set($property,$value)
56
+	public function  __set($property, $value)
57 57
 	{
58 58
 		$this->properties[$property] = $value;
59 59
 	}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	{
127 127
 		$num_args = (int) func_num_args(); // get number of arguments passed to
128 128
 
129
-		if ($num_args == 0 ||  $num_args > 1) {
129
+		if ($num_args == 0 || $num_args > 1) {
130 130
 
131 131
 			throw NoArgumentPassedToFunctionException::noArgumentPassedToFunction("Argument missing: only one argument is allowed");
132 132
 		}
@@ -153,12 +153,12 @@  discard block
 block discarded – undo
153 153
 
154 154
 		$num_args = (int) func_num_args(); // get number of arguments passed to
155 155
 
156
-		if ($num_args == 0 ||  $num_args > 1) {
156
+		if ($num_args == 0 || $num_args > 1) {
157 157
 
158 158
 			throw NoArgumentPassedToFunctionException::noArgumentPassedToFunction("Argument missing: only one argument is allowed");
159 159
 		}
160 160
 
161
-		$boolDeleted = DatabaseHandler::delete($id,self::getClassName());
161
+		$boolDeleted = DatabaseHandler::delete($id, self::getClassName());
162 162
 
163 163
 		if ($boolDeleted) {
164 164
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 	 */
190 190
 	public function checkIfRecordIsEmpty($arrayOfRecord)
191 191
 	{
192
-		if (count($arrayOfRecord) > 0 ) {
192
+		if (count($arrayOfRecord) > 0) {
193 193
 
194 194
 			return true;
195 195
 		}
Please login to merge, or discard this patch.
src/Database/DatabaseConnection.php 2 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
 	private
18 18
 		$databaseName,
19 19
 		$databaseHost,
20
-	    $databaseDriver,
21
-	    $databaseUsername,
22
-	    $databasePassword,
23
-	    $databaseHandle,
24
-        $envFileLoader;
20
+		$databaseDriver,
21
+		$databaseUsername,
22
+		$databasePassword,
23
+		$databaseHandle,
24
+		$envFileLoader;
25 25
 
26 26
 	public  function  __construct()
27 27
 	{
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 
107 107
 			//$dotenv = new Dotenv($_SERVER['DOCUMENT_ROOT']);
108 108
 			$dotenv = new Dotenv(__DIR__.'/../../');
109
-		    $dotenv->load();
109
+			$dotenv->load();
110 110
 		}
111 111
 
112 112
 	}
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 
30 30
 		$this->databaseHandle   = $this->connect(); // database connection handle
31 31
 
32
-		$this->databaseName     =  getenv('databaseName');
33
-		$this->databaseHost     =  getenv('databaseHost');
34
-		$this->databaseDriver   =  getenv('databaseDriver');
35
-		$this->databaseUsername =  getenv('databaseUsername');
36
-		$this->databasePassword =  getenv('databasePassword');
32
+		$this->databaseName     = getenv('databaseName');
33
+		$this->databaseHost     = getenv('databaseHost');
34
+		$this->databaseDriver   = getenv('databaseDriver');
35
+		$this->databaseUsername = getenv('databaseUsername');
36
+		$this->databasePassword = getenv('databasePassword');
37 37
 	}
38 38
 
39 39
 	/**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 			$databaseHandle = new PDO($this->getDatabaseDriver(), $this->databaseUsername, $this->databasePassword, $options);
56 56
 
57
-		} catch(PDOException $e) {
57
+		} catch (PDOException $e) {
58 58
 
59 59
 			return $e->getMessage();
60 60
 
@@ -78,21 +78,21 @@  discard block
 block discarded – undo
78 78
 			case 'mysql':
79 79
 
80 80
 				// Set DSN
81
-				$dsn = 'mysql:host='.    $this->databaseHost. ';dbname='. $this->databaseName;
81
+				$dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName;
82 82
 				break;
83 83
 			case 'sqlite':
84 84
 
85 85
 				// Set DSN
86
-				$dsn = 'sqlite:host='.   $this->databaseHost. ';dbname='. $this->databaseName;
86
+				$dsn = 'sqlite:host='.$this->databaseHost.';dbname='.$this->databaseName;
87 87
 				break;
88 88
 			case 'pgsql':
89 89
 
90 90
 				// Set DSN
91
-				$dsn = 'pgsqlsql:host='. $this->databaseHost. ';dbname='. $this->databaseName;
91
+				$dsn = 'pgsqlsql:host='.$this->databaseHost.';dbname='.$this->databaseName;
92 92
 				break;
93 93
 			default:
94 94
 				// Set DSN
95
-				$dsn = 'mysql:host='.    $this->databaseHost. ';dbname='. $this->databaseName;
95
+				$dsn = 'mysql:host='.$this->databaseHost.';dbname='.$this->databaseName;
96 96
 		}
97 97
 		return $dsn;
98 98
 	}
Please login to merge, or discard this patch.
src/Database/DatabaseHelper.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Helper/Inflector.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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) {
Please login to merge, or discard this patch.
src/Exception/TableFieldUndefinedException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@
 block discarded – undo
12 12
 
13 13
 class TableFieldUndefinedException extends Exception {
14 14
 
15
-	public static function fieldsNotDefinedException($fieldsNotDefined,$message)
15
+	public static function fieldsNotDefinedException($fieldsNotDefined, $message)
16 16
 	{
17
-		$splittedArray = implode(",",$fieldsNotDefined);
17
+		$splittedArray = implode(",", $fieldsNotDefined);
18 18
 
19
-		return new static ($splittedArray."  ".$message );
19
+		return new static ($splittedArray."  ".$message);
20 20
 	}
21 21
 
22 22
 }
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
src/Exception/NullArgumentPassedToFunctionException.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 
11 11
 use Exception;
12 12
 
13
-class NullArgumentPassedToFunction  extends  Exception{
13
+class NullArgumentPassedToFunction  extends  Exception {
14 14
 
15 15
 	public static function nullArgumentPassedToFunction($message)
16 16
 	{
Please login to merge, or discard this patch.
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: andela
5
- * Date: 2/22/16
6
- * Time: 9:38 PM
7
- */
3
+	 * Created by PhpStorm.
4
+	 * User: andela
5
+	 * Date: 2/22/16
6
+	 * Time: 9:38 PM
7
+	 */
8 8
 
9 9
 namespace Laztopaz\potatoORM;
10 10
 
Please login to merge, or discard this patch.