Completed
Branch master (810804)
by Opeyemi
15:47
created
src/Connections/MySqlConnection.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@
 block discarded – undo
12 12
     {
13 13
         $this->useDbEnv();
14 14
 
15
-        $dsn = 'mysql:host='.$this->_host
16
-                .';port='.$this->_port
17
-                .';dbname='.$this->_database;
15
+        $dsn = 'mysql:host=' . $this->_host
16
+                .';port=' . $this->_port
17
+                .';dbname=' . $this->_database;
18 18
 
19 19
         try {
20 20
             $this->_pdo = new PDO($dsn, $this->_username, $this->_password);
Please login to merge, or discard this patch.
Unused Use Statements   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace Opeyemiabiodun\PotatoORM\Connections;
4 4
 
5
-use PDO;
6
-use PDOException;
7 5
 use InvalidArgumentException;
8 6
 use Opeyemiabiodun\PotatoORM\Connections\Connection;
9
-use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait;
10 7
 use Opeyemiabiodun\PotatoORM\Connections\DatabaseTransactionsTrait;
8
+use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait;
9
+use PDO;
10
+use PDOException;
11 11
 
12 12
 final class MySqlConnection implements Connection
13 13
 {
Please login to merge, or discard this patch.
src/Models/Model.php 3 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,12 +2,12 @@
 block discarded – undo
2 2
 
3 3
 namespace Opeyemiabiodun\PotatoORM\Models;
4 4
 
5
-use RuntimeException;
6 5
 use InvalidArgumentException;
7 6
 use Opeyemiabiodun\PotatoORM\Connections\Connection;
8 7
 use Opeyemiabiodun\PotatoORM\Connections\PgSqlConnection;
9 8
 use Opeyemiabiodun\PotatoORM\Exceptions\AssignmentException;
10 9
 use Opeyemiabiodun\PotatoORM\Exceptions\PropertyNotFoundException;
10
+use RuntimeException;
11 11
 
12 12
 trait Model
13 13
 {
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      *
124 124
      * @param int $number Specifies which model instance to find; the 1st, 2nd, 3rd, .....
125 125
      *
126
-     * @return array Returns the particular instance of the model.
126
+     * @return Model Returns the particular instance of the model.
127 127
      */
128 128
     public static function find($number)
129 129
     {
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
     /**
207 207
      * Sets the model's connection.
208 208
      *
209
-     * @param Opeyemiabiodun\PotatoORM\Connections\Connection $connection An instance of Opeyemiabiodun\PotatoORM\Connections\Connection.
209
+     * @param Connection $connection An instance of Opeyemiabiodun\PotatoORM\Connections\Connection.
210 210
      */
211 211
     protected function setConnection(Connection $connection)
212 212
     {
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
         }
53 53
 
54 54
         if (null === $table) {
55
-            $table = strtolower(substr(get_class($this),strripos(get_class($this), "\\") + 1))."_table";
55
+            $table = strtolower(substr(get_class($this), strripos(get_class($this), "\\") + 1)) . "_table";
56 56
         }
57 57
 
58 58
         $this->setConnection($connection);
59 59
         $this->setTable($table);
60 60
 
61
-        if (! empty($array)) {
61
+        if (!empty($array)) {
62 62
             $this->setProperties($array);
63 63
         }
64 64
     }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
         if (array_key_exists($property, $this->_attributes)) {
76 76
             return $this->_attributes[$property];
77 77
         } else {
78
-            throw new PropertyNotFoundException("The ".get_class($this)." instance has no {$property} property.");
78
+            throw new PropertyNotFoundException("The " . get_class($this) . " instance has no {$property} property.");
79 79
         }
80 80
     }
81 81
 
@@ -87,14 +87,14 @@  discard block
 block discarded – undo
87 87
      */
88 88
     public function __set($property, $value)
89 89
     {
90
-        if (! is_scalar($value)) {
90
+        if (!is_scalar($value)) {
91 91
             throw new AssignmentException("Only scalar values can be assigned to the {$property} property.");
92 92
         }
93 93
 
94 94
         if (array_key_exists($property, $this->_attributes)) {
95 95
             $this->_attributes[$property] = $value;
96 96
         } else {
97
-            throw new PropertyNotFoundException("The ".get_class($this)." instance has no {$property} property.");
97
+            throw new PropertyNotFoundException("The " . get_class($this) . " instance has no {$property} property.");
98 98
         }
99 99
     }
100 100
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      */
108 108
     public static function destroy($number)
109 109
     {
110
-        if (! is_int($number)) {
110
+        if (!is_int($number)) {
111 111
             throw new InvalidArgumentException("The parameter {$number} is not an integer. An integer is required instead.");
112 112
         }
113 113
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public static function find($number)
129 129
     {
130
-        if (! is_int($number)) {
130
+        if (!is_int($number)) {
131 131
             throw new InvalidArgumentException("The parameter {$number} is not an integer. An integer is required instead.");
132 132
         }
133 133
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         $count = count($records);
157 157
         $result = [];
158 158
 
159
-        for ($i=0; $i < $count ; $i++) { 
159
+        for ($i = 0; $i < $count; $i++) { 
160 160
             array_push($result, new self($records[$i]));
161 161
         }
162 162
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
         $hasAttributes = false;
174 174
 
175 175
         foreach ($this->_attributes as $key => $value) {
176
-            if (! is_null($value)) {
176
+            if (!is_null($value)) {
177 177
                 $hasAttributes = true;
178 178
             }
179 179
         }
@@ -188,11 +188,11 @@  discard block
 block discarded – undo
188 188
      */
189 189
     public function save()
190 190
     {
191
-        if (! $this->hasAttributes()) {
192
-            throw new RuntimeException(get_class($this)." model has nothing to persist to the database.");
191
+        if (!$this->hasAttributes()) {
192
+            throw new RuntimeException(get_class($this) . " model has nothing to persist to the database.");
193 193
         }
194 194
 
195
-        $pk = (empty($this->_attributes[self::$_primaryKey])) ? "NULL" :  $this->_attributes[self::$_primaryKey];
195
+        $pk = (empty($this->_attributes[self::$_primaryKey])) ? "NULL" : $this->_attributes[self::$_primaryKey];
196 196
 
197 197
         #$record = self::$_connection->findRecord(self::$_table, (string) $pk);
198 198
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
     {
223 223
         foreach ($this->_attributes as $key => $value) {
224 224
 
225
-            if (! empty($array[$key])) {
225
+            if (!empty($array[$key])) {
226 226
                 $this->_attributes[$key] = $array[$key];
227 227
             }
228 228
 
Please login to merge, or discard this patch.
src/Connections/LoadEnvVariablesTrait.php 2 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 
3 3
 namespace Opeyemiabiodun\PotatoORM\Connections;
4 4
 
5
-use Exception;
6 5
 use Dotenv\Dotenv;
6
+use Exception;
7 7
 use RuntimeException;
8 8
 
9 9
 trait LoadEnvVariablesTrait
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
      */
58 58
     private function loadDbEnv()
59 59
     {
60
-        $dotenv = new Dotenv(__DIR__.'/../..');
60
+        $dotenv = new Dotenv(__DIR__ . '/../..');
61 61
         $dotenv->load();
62 62
 
63 63
         $dotenv->required(['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_PORT'])->notEmpty();
Please login to merge, or discard this patch.
src/Connections/PgSqlConnection.php 1 patch
Unused Use Statements   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 
3 3
 namespace Opeyemiabiodun\PotatoORM\Connections;
4 4
 
5
-use PDO;
6
-use PDOException;
7
-use RuntimeException;
8 5
 use InvalidArgumentException;
9 6
 use Opeyemiabiodun\PotatoORM\Connections\Connection;
10
-use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait;
11 7
 use Opeyemiabiodun\PotatoORM\Connections\DatabaseTransactionsTrait;
8
+use Opeyemiabiodun\PotatoORM\Connections\LoadEnvVariablesTrait;
9
+use PDO;
10
+use PDOException;
11
+use RuntimeException;
12 12
 
13 13
 final class PgSqlConnection implements Connection
14 14
 {
Please login to merge, or discard this patch.
src/Connections/DatabaseTransactionsTrait.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -36,9 +36,9 @@  discard block
 block discarded – undo
36 36
             }
37 37
 
38 38
             if ($count > 0) {
39
-                $sql = $sql."{$key}, ";
39
+                $sql = $sql . "{$key}, ";
40 40
             } else {
41
-                $sql = $sql."{$key}) ";
41
+                $sql = $sql . "{$key}) ";
42 42
             }
43 43
         }
44 44
 
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
             }
55 55
 
56 56
             if ($count > 0) {
57
-                $sql = (empty($value)) ? $sql."NULL, " : $sql."'{$value}', ";
57
+                $sql = (empty($value)) ? $sql . "NULL, " : $sql . "'{$value}', ";
58 58
             } else {
59
-                $sql = (empty($value)) ? $sql."NULL " : $sql."'{$value}') ";
59
+                $sql = (empty($value)) ? $sql . "NULL " : $sql . "'{$value}') ";
60 60
             }
61 61
         }
62 62
 
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 
152 152
             if ($count > 0) {
153 153
 
154
-                $sql = $sql."{$key}='{$value}', ";
154
+                $sql = $sql . "{$key}='{$value}', ";
155 155
 
156 156
             } else {
157 157
 
158
-                $sql = $sql."{$key}='{$value}' ";
158
+                $sql = $sql . "{$key}='{$value}' ";
159 159
 
160 160
             }
161 161
         }
Please login to merge, or discard this patch.
src/Connections/ConnectionFactory.php 4 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,8 +3,8 @@
 block discarded – undo
3 3
 namespace Opeyemiabiodun\PotatoORM\Connections;
4 4
 
5 5
 use Dotenv\Dotenv;
6
-use Opeyemiabiodun\PotatoORM\Connections\PgSqlConnection;
7 6
 use Opeyemiabiodun\PotatoORM\Connections\MySqlConnection;
7
+use Opeyemiabiodun\PotatoORM\Connections\PgSqlConnection;
8 8
 use Opeyemiabiodun\PotatoORM\Connections\SqliteConnection;
9 9
 
10 10
 class ConnectionFactory
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
 	public static function load()
17 17
 	{
18 18
 
19
-                $dotenv = new Dotenv(__DIR__.'/../..');
19
+                $dotenv = new Dotenv(__DIR__ . '/../..');
20 20
                 $dotenv->load();
21 21
 
22 22
                 $dotenv->required(['DB_ENGINE'])->allowedValues(['mysql', 'pgsql', 'sqlite']);
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -19,6 +19,9 @@
 block discarded – undo
19 19
 	{
20 20
 	}
21 21
 
22
+	/**
23
+	 * @return Connection
24
+	 */
22 25
 	public static function load()
23 26
 	{
24 27
                 
Please login to merge, or discard this patch.
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,12 +15,12 @@  discard block
 block discarded – undo
15 15
 
16 16
         private static $_sqliteConnection;
17 17
 
18
-	private function __construct()
19
-	{
20
-	}
18
+    private function __construct()
19
+    {
20
+    }
21 21
 
22
-	public static function load()
23
-	{
22
+    public static function load()
23
+    {
24 24
                 
25 25
                 $dotenv = new Dotenv(__DIR__.'/../..');
26 26
                 $dotenv->load();
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 
30 30
                 switch (getenv('DB_ENGINE')) 
31 31
                 {
32
-                	case 'mysql':
32
+                    case 'mysql':
33 33
                                 if (self::$_mySqlConnection == null) {
34 34
                                         self::$_mySqlConnection = new MySqlConnection();        
35 35
                                 } 
36
-        		        return self::$_mySqlConnection;
36
+                        return self::$_mySqlConnection;
37 37
 
38
-        		case 'pgsql':
38
+                case 'pgsql':
39 39
                                 if (self::$_pgSqlConnection == null) {
40 40
                                         self::$_pgSqlConnection = new PgSqlConnection();        
41 41
                                 } 
@@ -47,5 +47,5 @@  discard block
 block discarded – undo
47 47
                                 } 
48 48
                                 return self::$_sqliteConnection;
49 49
                 }		
50
-	}
50
+    }
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
src/Connections/SqliteConnection.php 2 patches
Unused Use Statements   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,12 +2,11 @@
 block discarded – undo
2 2
 
3 3
 namespace Opeyemiabiodun\PotatoORM\Connections;
4 4
 
5
-use PDO;
6
-use PDOException;
7
-use RuntimeException;
8 5
 use InvalidArgumentException;
9 6
 use Opeyemiabiodun\PotatoORM\Connections\Connection;
10 7
 use Opeyemiabiodun\PotatoORM\Connections\DatabaseTransactionsTrait;
8
+use PDO;
9
+use PDOException;
11 10
 
12 11
 final class SqliteConnection implements Connection
13 12
 {
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -95,6 +95,9 @@
 block discarded – undo
95 95
         return $this->keys[$table][0];
96 96
     }
97 97
 
98
+    /**
99
+     * @param string $table
100
+     */
98 101
     private function loadColumnInfo($table)
99 102
     {
100 103
         $query     = "PRAGMA table_info('{$table}')";
Please login to merge, or discard this patch.
src/Models/User.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,9 +7,9 @@
 block discarded – undo
7 7
 
8 8
 class User
9 9
 {
10
-	use Model;
10
+    use Model;
11 11
 
12
-	public static function createTable(PDO $pdo)
12
+    public static function createTable(PDO $pdo)
13 13
     {
14 14
         $pdo->query("CREATE TABLE user_table
15 15
         				(
Please login to merge, or discard this patch.