Completed
Branch develop (bcdff2)
by Michael
04:41 queued 01:33
created
src/AbstractActiveRecord.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -155,7 +155,7 @@
 block discarded – undo
155 155
 	/**
156 156
 	 * Returns the PDO.
157 157
 	 *
158
-	 * @return PDO the PDO.
158
+	 * @return \PDO the PDO.
159 159
 	 */
160 160
 	public function getPdo()
161 161
 	{
Please login to merge, or discard this patch.
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -17,172 +17,172 @@
 block discarded – undo
17 17
  */
18 18
 abstract class AbstractActiveRecord implements ActiveRecordInterface
19 19
 {
20
-	/** @var \PDO The PDO object. */
21
-	private $pdo;
22
-
23
-	/** @var null|int The ID. */
24
-	private $id;
25
-
26
-	/**
27
-	 * Construct an abstract pdo active record with the given pdo.
28
-	 *
29
-	 * @param \PDO $pdo
30
-	 */
31
-	public function __construct(\PDO $pdo)
32
-	{
33
-		$this->pdo = $pdo;
34
-		$this->id = null;
35
-
36
-		// TODO enable PDO exceptions?
37
-	}
38
-
39
-	/**
40
-	 * {@inheritdoc}
41
-	 */
42
-	public function create()
43
-	{
44
-		$pdoStatement = $this->pdo->prepare($this->getCreateQuery());
45
-		$pdoStatement->execute($this->getActiveRecordData());
46
-
47
-		$this->id = intval($this->pdo->lastInsertId());
48
-		return $this;
49
-	}
50
-
51
-	/**
52
-	 * Returns the create query.
53
-	 *
54
-	 * @return string the create query.
55
-	 */
56
-	private function getCreateQuery()
57
-	{
58
-		$columns = array_keys($this->getActiveRecordData());
59
-		$values = [];
60
-
61
-		foreach ($columns as $key => $value) {
62
-			$values[] = ':' . $value;
63
-		}
64
-
65
-		return sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->getActiveRecordName(), implode(', ', $columns), implode(', ', $values));
66
-	}
67
-
68
-	/**
69
-	 * {@inheritdoc}
70
-	 */
71
-	public function read($id)
72
-	{
73
-		$data = $this->getActiveRecordData();
74
-
75
-		$pdoStatement = $this->pdo->prepare($this->getReadQuery());
76
-		$pdoStatement->execute(['id' => $id]);
77
-		$result = $pdoStatement->fetch(\PDO::FETCH_ASSOC);
78
-
79
-		$this->id = $id;
80
-
81
-		foreach ($data as $key => &$value) {
82
-			$value = $result[$key];
83
-		}
84
-
85
-		return $this;
86
-	}
87
-
88
-	/**
89
-	 * Returns the read query.
90
-	 *
91
-	 * @return string the read query.
92
-	 */
93
-	private function getReadQuery()
94
-	{
95
-		return sprintf('SELECT * FROM `%s` WHERE `id` = :id', $this->getActiveRecordName());
96
-	}
97
-
98
-	/**
99
-	 * {@inheritdoc}
100
-	 */
101
-	public function update()
102
-	{
103
-		$pdoStatement = $this->pdo->prepare($this->getUpdateQuery());
104
-		$pdoStatement->execute(['id' => $this->id] + $this->getActiveRecordData());
105
-
106
-		return $this;
107
-	}
108
-
109
-	/**
110
-	 * Returns the update query.
111
-	 *
112
-	 * @return string the update query.
113
-	 */
114
-	private function getUpdateQuery()
115
-	{
116
-		$values = [];
117
-
118
-		foreach (array_keys($this->getActiveRecordData()) as $key => $value) {
119
-			$values[] = $value . ' = :' . $value;
120
-		}
121
-
122
-		return sprintf('UPDATE %s SET %s WHERE `id` = :id', $this->getActiveRecordName(), implode(', ', $values));
123
-	}
124
-
125
-	/**
126
-	 * {@inheritdoc}
127
-	 */
128
-	public function delete()
129
-	{
130
-		$pdoStatement = $this->pdo->prepare($this->getDeleteQuery());
131
-		$pdoStatement->execute(['id' => $this->id]);
132
-
133
-		$this->id = null;
134
-		return $this;
135
-	}
136
-
137
-	/**
138
-	 * Returns the delete query.
139
-	 *
140
-	 * @return string the delete query.
141
-	 */
142
-	private function getDeleteQuery()
143
-	{
144
-		return sprintf('SELECT * FROM `%s` WHERE `id` = :id', $this->getActiveRecordName());
145
-	}
146
-
147
-	/**
148
-	 * {@inheritdoc}
149
-	 */
150
-	public function exists()
151
-	{
152
-		return $this->id !== null;
153
-	}
154
-
155
-	/**
156
-	 * Returns the PDO.
157
-	 *
158
-	 * @return PDO the PDO.
159
-	 */
160
-	public function getPdo()
161
-	{
162
-		return $this->pdo;
163
-	}
164
-
165
-	/**
166
-	 * Returns the ID.
167
-	 *
168
-	 * @return null|int The ID.
169
-	 */
170
-	public function getId()
171
-	{
172
-		return $this->id;
173
-	}
174
-
175
-	/**
176
-	 * Returns the active record name.
177
-	 *
178
-	 * @return string the active record name.
179
-	 */
180
-	abstract protected function getActiveRecordName();
181
-
182
-	/**
183
-	 * Returns the active record data.
184
-	 *
185
-	 * @return array the active record data.
186
-	 */
187
-	abstract protected function getActiveRecordData();
20
+    /** @var \PDO The PDO object. */
21
+    private $pdo;
22
+
23
+    /** @var null|int The ID. */
24
+    private $id;
25
+
26
+    /**
27
+     * Construct an abstract pdo active record with the given pdo.
28
+     *
29
+     * @param \PDO $pdo
30
+     */
31
+    public function __construct(\PDO $pdo)
32
+    {
33
+        $this->pdo = $pdo;
34
+        $this->id = null;
35
+
36
+        // TODO enable PDO exceptions?
37
+    }
38
+
39
+    /**
40
+     * {@inheritdoc}
41
+     */
42
+    public function create()
43
+    {
44
+        $pdoStatement = $this->pdo->prepare($this->getCreateQuery());
45
+        $pdoStatement->execute($this->getActiveRecordData());
46
+
47
+        $this->id = intval($this->pdo->lastInsertId());
48
+        return $this;
49
+    }
50
+
51
+    /**
52
+     * Returns the create query.
53
+     *
54
+     * @return string the create query.
55
+     */
56
+    private function getCreateQuery()
57
+    {
58
+        $columns = array_keys($this->getActiveRecordData());
59
+        $values = [];
60
+
61
+        foreach ($columns as $key => $value) {
62
+            $values[] = ':' . $value;
63
+        }
64
+
65
+        return sprintf('INSERT INTO %s (%s) VALUES (%s)', $this->getActiveRecordName(), implode(', ', $columns), implode(', ', $values));
66
+    }
67
+
68
+    /**
69
+     * {@inheritdoc}
70
+     */
71
+    public function read($id)
72
+    {
73
+        $data = $this->getActiveRecordData();
74
+
75
+        $pdoStatement = $this->pdo->prepare($this->getReadQuery());
76
+        $pdoStatement->execute(['id' => $id]);
77
+        $result = $pdoStatement->fetch(\PDO::FETCH_ASSOC);
78
+
79
+        $this->id = $id;
80
+
81
+        foreach ($data as $key => &$value) {
82
+            $value = $result[$key];
83
+        }
84
+
85
+        return $this;
86
+    }
87
+
88
+    /**
89
+     * Returns the read query.
90
+     *
91
+     * @return string the read query.
92
+     */
93
+    private function getReadQuery()
94
+    {
95
+        return sprintf('SELECT * FROM `%s` WHERE `id` = :id', $this->getActiveRecordName());
96
+    }
97
+
98
+    /**
99
+     * {@inheritdoc}
100
+     */
101
+    public function update()
102
+    {
103
+        $pdoStatement = $this->pdo->prepare($this->getUpdateQuery());
104
+        $pdoStatement->execute(['id' => $this->id] + $this->getActiveRecordData());
105
+
106
+        return $this;
107
+    }
108
+
109
+    /**
110
+     * Returns the update query.
111
+     *
112
+     * @return string the update query.
113
+     */
114
+    private function getUpdateQuery()
115
+    {
116
+        $values = [];
117
+
118
+        foreach (array_keys($this->getActiveRecordData()) as $key => $value) {
119
+            $values[] = $value . ' = :' . $value;
120
+        }
121
+
122
+        return sprintf('UPDATE %s SET %s WHERE `id` = :id', $this->getActiveRecordName(), implode(', ', $values));
123
+    }
124
+
125
+    /**
126
+     * {@inheritdoc}
127
+     */
128
+    public function delete()
129
+    {
130
+        $pdoStatement = $this->pdo->prepare($this->getDeleteQuery());
131
+        $pdoStatement->execute(['id' => $this->id]);
132
+
133
+        $this->id = null;
134
+        return $this;
135
+    }
136
+
137
+    /**
138
+     * Returns the delete query.
139
+     *
140
+     * @return string the delete query.
141
+     */
142
+    private function getDeleteQuery()
143
+    {
144
+        return sprintf('SELECT * FROM `%s` WHERE `id` = :id', $this->getActiveRecordName());
145
+    }
146
+
147
+    /**
148
+     * {@inheritdoc}
149
+     */
150
+    public function exists()
151
+    {
152
+        return $this->id !== null;
153
+    }
154
+
155
+    /**
156
+     * Returns the PDO.
157
+     *
158
+     * @return PDO the PDO.
159
+     */
160
+    public function getPdo()
161
+    {
162
+        return $this->pdo;
163
+    }
164
+
165
+    /**
166
+     * Returns the ID.
167
+     *
168
+     * @return null|int The ID.
169
+     */
170
+    public function getId()
171
+    {
172
+        return $this->id;
173
+    }
174
+
175
+    /**
176
+     * Returns the active record name.
177
+     *
178
+     * @return string the active record name.
179
+     */
180
+    abstract protected function getActiveRecordName();
181
+
182
+    /**
183
+     * Returns the active record data.
184
+     *
185
+     * @return array the active record data.
186
+     */
187
+    abstract protected function getActiveRecordData();
188 188
 }
Please login to merge, or discard this patch.
src/AbstractActiveRecordSearch.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -17,65 +17,65 @@
 block discarded – undo
17 17
  */
18 18
 abstract class AbstractActiveRecordSearch extends AbstractActiveRecord
19 19
 {
20
-	/**
21
-	 * {@inheritdoc}
22
-	 */
23
-	public function search($options = [])
24
-	{
25
-		$name = $this->getActiveRecordName();
26
-		$data = $this->getActiveRecordData();
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    public function search($options = [])
24
+    {
25
+        $name = $this->getActiveRecordName();
26
+        $data = $this->getActiveRecordData();
27 27
 
28
-		$pdoStatement = $this->getPdo()->prepare($this->getSearchQuery($options));
29
-		array_walk_recursive($options, function (&$value) use ($pdoStatement) {
30
-			static $index = 1;
28
+        $pdoStatement = $this->getPdo()->prepare($this->getSearchQuery($options));
29
+        array_walk_recursive($options, function (&$value) use ($pdoStatement) {
30
+            static $index = 1;
31 31
 
32
-			$pdoStatement->bindParam($index++, $value);
33
-		});
32
+            $pdoStatement->bindParam($index++, $value);
33
+        });
34 34
 
35
-		$pdoStatement->execute();
36
-		$result = [];
35
+        $pdoStatement->execute();
36
+        $result = [];
37 37
 
38
-		while ($row = $pdoStatement->fetch()) {
39
-			$x = new static($this->getPdo());
40
-			$x->id = intval($row['id']);
38
+        while ($row = $pdoStatement->fetch()) {
39
+            $x = new static($this->getPdo());
40
+            $x->id = intval($row['id']);
41 41
 
42
-			foreach ($x->getActiveRecordData() as $key => &$value) {
43
-				$value = $row[$key];
44
-			}
42
+            foreach ($x->getActiveRecordData() as $key => &$value) {
43
+                $value = $row[$key];
44
+            }
45 45
 
46
-			$result[] = $x;
47
-		}
46
+            $result[] = $x;
47
+        }
48 48
 
49
-		return $result;
50
-	}
49
+        return $result;
50
+    }
51 51
 
52
-	/**
53
-	 * Returns the search query with the given options.
54
-	 *
55
-	 * @param arrray $options = []
56
-	 * @return string the search query with the given options.
57
-	 */
58
-	private function getSearchQuery($options = [])
59
-	{
60
-		$columns = array_keys($this->getActiveRecordData());
61
-		$values = [];
52
+    /**
53
+     * Returns the search query with the given options.
54
+     *
55
+     * @param arrray $options = []
56
+     * @return string the search query with the given options.
57
+     */
58
+    private function getSearchQuery($options = [])
59
+    {
60
+        $columns = array_keys($this->getActiveRecordData());
61
+        $values = [];
62 62
 
63
-		foreach ($options as $key => $value) {
64
-			if (!in_array($key, $columns)) {
65
-				throw new ActiveRecordException('Invalid option key.');
66
-			}
63
+        foreach ($options as $key => $value) {
64
+            if (!in_array($key, $columns)) {
65
+                throw new ActiveRecordException('Invalid option key.');
66
+            }
67 67
 
68
-			if (is_int($value)) {
69
-				$values[] = $key . ' = ?';
70
-			} elseif (is_string($value)) {
71
-				$values[] = $key . ' LIKE ?';
72
-			} elseif(is_array($value) && !empty($value)) {
73
-				$values[] = $key . ' IN(' . implode(',', array_fill(0, count($value), '?')) . ')';
74
-			} else {
75
-				throw new ActiveRecordException('Invalid option value.');
76
-			}
77
-		}
68
+            if (is_int($value)) {
69
+                $values[] = $key . ' = ?';
70
+            } elseif (is_string($value)) {
71
+                $values[] = $key . ' LIKE ?';
72
+            } elseif(is_array($value) && !empty($value)) {
73
+                $values[] = $key . ' IN(' . implode(',', array_fill(0, count($value), '?')) . ')';
74
+            } else {
75
+                throw new ActiveRecordException('Invalid option value.');
76
+            }
77
+        }
78 78
 
79
-		return sprintf('SELECT * FROM %s %s %s', $this->getActiveRecordName(), empty($values) ? '' : 'WHERE', implode(' AND ', $values));
80
-	}
79
+        return sprintf('SELECT * FROM %s %s %s', $this->getActiveRecordName(), empty($values) ? '' : 'WHERE', implode(' AND ', $values));
80
+    }
81 81
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 		$data = $this->getActiveRecordData();
27 27
 
28 28
 		$pdoStatement = $this->getPdo()->prepare($this->getSearchQuery($options));
29
-		array_walk_recursive($options, function (&$value) use ($pdoStatement) {
29
+		array_walk_recursive($options, function(&$value) use ($pdoStatement) {
30 30
 			static $index = 1;
31 31
 
32 32
 			$pdoStatement->bindParam($index++, $value);
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 				$values[] = $key . ' = ?';
70 70
 			} elseif (is_string($value)) {
71 71
 				$values[] = $key . ' LIKE ?';
72
-			} elseif(is_array($value) && !empty($value)) {
72
+			} elseif (is_array($value) && !empty($value)) {
73 73
 				$values[] = $key . ' IN(' . implode(',', array_fill(0, count($value), '?')) . ')';
74 74
 			} else {
75 75
 				throw new ActiveRecordException('Invalid option value.');
Please login to merge, or discard this patch.
src/ActiveRecordInterface.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -19,43 +19,43 @@
 block discarded – undo
19 19
  */
20 20
 interface ActiveRecordInterface
21 21
 {
22
-	/**
23
-	 * Create the record.
24
-	 *
25
-	 * @return $this
26
-	 * @throws ActiveRecordException on failure.
27
-	 */
28
-	public function create();
22
+    /**
23
+     * Create the record.
24
+     *
25
+     * @return $this
26
+     * @throws ActiveRecordException on failure.
27
+     */
28
+    public function create();
29 29
 
30
-	/**
31
-	 * Read the record with the given ID.
32
-	 *
33
-	 * @param int $id
34
-	 * @return $this
35
-	 * @throws ActiveRecordException on failure.
36
-	 */
37
-	public function read($id);
30
+    /**
31
+     * Read the record with the given ID.
32
+     *
33
+     * @param int $id
34
+     * @return $this
35
+     * @throws ActiveRecordException on failure.
36
+     */
37
+    public function read($id);
38 38
 
39
-	/**
40
-	 * Update the record.
41
-	 *
42
-	 * @return $this
43
-	 * @throws ActiveRecordException on failure.
44
-	 */
45
-	public function update();
39
+    /**
40
+     * Update the record.
41
+     *
42
+     * @return $this
43
+     * @throws ActiveRecordException on failure.
44
+     */
45
+    public function update();
46 46
 
47
-	/**
48
-	 * Delete the record.
49
-	 *
50
-	 * @return $this
51
-	 * @throws ActiveRecordException on failure.
52
-	 */
53
-	public function delete();
47
+    /**
48
+     * Delete the record.
49
+     *
50
+     * @return $this
51
+     * @throws ActiveRecordException on failure.
52
+     */
53
+    public function delete();
54 54
 
55
-	/**
56
-	 * Returns true if the record exists.
57
-	 *
58
-	 * @return bool true if the records exists.
59
-	 */
60
-	public function exists();
55
+    /**
56
+     * Returns true if the record exists.
57
+     *
58
+     * @return bool true if the records exists.
59
+     */
60
+    public function exists();
61 61
 }
Please login to merge, or discard this patch.
src/ActiveRecordSearchInterface.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@
 block discarded – undo
17 17
  */
18 18
 interface ActiveRecordSearchInterface extends ActiveRecordInterface
19 19
 {
20
-	/**
21
-	 * Returns the records with the given options.
22
-	 *
23
-	 * @param array $options = []
24
-	 * @return static[] the records with the given options.
25
-	 * @throws ActiveRecordException on failure.
26
-	 */
27
-	public function search($options = []);
20
+    /**
21
+     * Returns the records with the given options.
22
+     *
23
+     * @param array $options = []
24
+     * @return static[] the records with the given options.
25
+     * @throws ActiveRecordException on failure.
26
+     */
27
+    public function search($options = []);
28 28
 }
Please login to merge, or discard this patch.