Completed
Push — develop ( aedfc7...dd4085 )
by Michael
03:13
created
src/AbstractActiveRecordSearch.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -17,63 +17,63 @@
 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
-		$pdoStatement = $this->getPdo()->prepare($this->getSearchQuery($options));
26
-		array_walk_recursive($options, function (&$value) use ($pdoStatement) {
27
-			static $index = 1;
20
+    /**
21
+     * {@inheritdoc}
22
+     */
23
+    public function search($options = [])
24
+    {
25
+        $pdoStatement = $this->getPdo()->prepare($this->getSearchQuery($options));
26
+        array_walk_recursive($options, function (&$value) use ($pdoStatement) {
27
+            static $index = 1;
28 28
 
29
-			$pdoStatement->bindParam($index++, $value);
30
-		});
29
+            $pdoStatement->bindParam($index++, $value);
30
+        });
31 31
 
32
-		$pdoStatement->execute();
33
-		$result = [];
32
+        $pdoStatement->execute();
33
+        $result = [];
34 34
 
35
-		while ($row = $pdoStatement->fetch()) {
36
-			$new = new static($this->getPdo());
37
-			$new->setId(intval($row['id']));
38
-			$data = $new->getActiveRecordData();
35
+        while ($row = $pdoStatement->fetch()) {
36
+            $new = new static($this->getPdo());
37
+            $new->setId(intval($row['id']));
38
+            $data = $new->getActiveRecordData();
39 39
 
40
-			foreach ($data as $key => &$value) {
41
-				$value = $row[$key];
42
-			}
40
+            foreach ($data as $key => &$value) {
41
+                $value = $row[$key];
42
+            }
43 43
 
44
-			$result[] = $new;
45
-		}
44
+            $result[] = $new;
45
+        }
46 46
 
47
-		return $result;
48
-	}
47
+        return $result;
48
+    }
49 49
 
50
-	/**
51
-	 * Returns the search query with the given options.
52
-	 *
53
-	 * @param array $options = []
54
-	 * @return string the search query with the given options.
55
-	 */
56
-	private function getSearchQuery($options = [])
57
-	{
58
-		$columns = array_keys($this->getActiveRecordData());
59
-		$values = [];
50
+    /**
51
+     * Returns the search query with the given options.
52
+     *
53
+     * @param array $options = []
54
+     * @return string the search query with the given options.
55
+     */
56
+    private function getSearchQuery($options = [])
57
+    {
58
+        $columns = array_keys($this->getActiveRecordData());
59
+        $values = [];
60 60
 
61
-		foreach ($options as $key => $value) {
62
-			if (!in_array($key, $columns)) {
63
-				throw new ActiveRecordException('Invalid option key.');
64
-			}
61
+        foreach ($options as $key => $value) {
62
+            if (!in_array($key, $columns)) {
63
+                throw new ActiveRecordException('Invalid option key.');
64
+            }
65 65
 
66
-			if (is_int($value)) {
67
-				$values[] = $key . ' = ?';
68
-			} elseif (is_string($value)) {
69
-				$values[] = $key . ' LIKE ?';
70
-			} elseif(is_array($value) && !empty($value)) {
71
-				$values[] = $key . ' IN(' . implode(',', array_fill(0, count($value), '?')) . ')';
72
-			} else {
73
-				throw new ActiveRecordException('Invalid option value.');
74
-			}
75
-		}
66
+            if (is_int($value)) {
67
+                $values[] = $key . ' = ?';
68
+            } elseif (is_string($value)) {
69
+                $values[] = $key . ' LIKE ?';
70
+            } elseif(is_array($value) && !empty($value)) {
71
+                $values[] = $key . ' IN(' . implode(',', array_fill(0, count($value), '?')) . ')';
72
+            } else {
73
+                throw new ActiveRecordException('Invalid option value.');
74
+            }
75
+        }
76 76
 
77
-		return sprintf('SELECT * FROM %s %s %s', $this->getActiveRecordName(), empty($values) ? '' : 'WHERE', implode(' AND ', $values));
78
-	}
77
+        return sprintf('SELECT * FROM %s %s %s', $this->getActiveRecordName(), empty($values) ? '' : 'WHERE', implode(' AND ', $values));
78
+    }
79 79
 }
Please login to merge, or discard this patch.