Passed
Push — master ( d44413...7ff405 )
by Adrian
04:24
created
sample/autoloader.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -10,14 +10,14 @@
 block discarded – undo
10 10
 /**
11 11
  * @param $class
12 12
  */
13
-    function($class) {
13
+	function($class) {
14 14
 
15
-        $nameSpace = str_replace('\\', '/', trim($class, '\\')) . '.php';
16
-        $nameSpace = str_replace('Qpdb/QueryBuilder/', '', $nameSpace);
17
-        $includeFile = __DIR__ . '/../src/' . $nameSpace;
15
+		$nameSpace = str_replace('\\', '/', trim($class, '\\')) . '.php';
16
+		$nameSpace = str_replace('Qpdb/QueryBuilder/', '', $nameSpace);
17
+		$includeFile = __DIR__ . '/../src/' . $nameSpace;
18 18
 
19
-        require_once($includeFile);
19
+		require_once($includeFile);
20 20
 
21
-    }
21
+	}
22 22
 
23 23
 );
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/InsertMultiple.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -17,110 +17,110 @@
 block discarded – undo
17 17
 trait InsertMultiple
18 18
 {
19 19
 
20
-    use Objects;
20
+	use Objects;
21 21
 
22 22
 
23
-    /**
24
-     * @param $fieldsList
25
-     * @param array $rowsForInsert
26
-     * @return $this
27
-     */
28
-    public function fromArray($fieldsList, array $rowsForInsert)
29
-    {
30
-        $this->setFieldsList($fieldsList);
23
+	/**
24
+	 * @param $fieldsList
25
+	 * @param array $rowsForInsert
26
+	 * @return $this
27
+	 */
28
+	public function fromArray($fieldsList, array $rowsForInsert)
29
+	{
30
+		$this->setFieldsList($fieldsList);
31 31
 
32
-        foreach ($rowsForInsert as $row)
33
-            $this->addSingleRow($row);
32
+		foreach ($rowsForInsert as $row)
33
+			$this->addSingleRow($row);
34 34
 
35
-        return $this;
36
-    }
35
+		return $this;
36
+	}
37 37
 
38 38
 
39
-    /**
40
-     * @param $fieldsList
41
-     * @param QuerySelect $query
42
-     * @return $this
43
-     */
44
-    public function fromQuerySelect($fieldsList, QuerySelect $query)
45
-    {
46
-        $this->setFieldsList($fieldsList);
39
+	/**
40
+	 * @param $fieldsList
41
+	 * @param QuerySelect $query
42
+	 * @return $this
43
+	 */
44
+	public function fromQuerySelect($fieldsList, QuerySelect $query)
45
+	{
46
+		$this->setFieldsList($fieldsList);
47 47
 
48
-        foreach ($query->getBindParams() as $key => $value)
49
-            $this->queryStructure->setParams($key, $value);
48
+		foreach ($query->getBindParams() as $key => $value)
49
+			$this->queryStructure->setParams($key, $value);
50 50
 
51
-        $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query);
51
+		$this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query);
52 52
 
53
-        return $this;
54
-    }
53
+		return $this;
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * @param string|array $fieldList
59
-     */
60
-    private function setFieldsList($fieldList)
61
-    {
62
-        if (!is_array($fieldList))
63
-            $fieldList = QueryHelper::explode($fieldList);
57
+	/**
58
+	 * @param string|array $fieldList
59
+	 */
60
+	private function setFieldsList($fieldList)
61
+	{
62
+		if (!is_array($fieldList))
63
+			$fieldList = QueryHelper::explode($fieldList);
64 64
 
65
-        $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList);
65
+		$this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList);
66 66
 
67
-    }
67
+	}
68 68
 
69
-    /**
70
-     * @param array $rowValues
71
-     * @return $this
72
-     * @throws QueryException
73
-     */
74
-    private function addSingleRow(array $rowValues)
75
-    {
69
+	/**
70
+	 * @param array $rowValues
71
+	 * @return $this
72
+	 * @throws QueryException
73
+	 */
74
+	private function addSingleRow(array $rowValues)
75
+	{
76 76
 
77
-        if ($this->getNumberOfFields() !== count($rowValues))
78
-            throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT);
77
+		if ($this->getNumberOfFields() !== count($rowValues))
78
+			throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT);
79 79
 
80
-        $pdoRowValues = array();
80
+		$pdoRowValues = array();
81 81
 
82
-        foreach ($rowValues as $value)
83
-            $pdoRowValues[] = $this->queryStructure->bindParam('value', $value);
82
+		foreach ($rowValues as $value)
83
+			$pdoRowValues[] = $this->queryStructure->bindParam('value', $value);
84 84
 
85
-        $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )';
85
+		$pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )';
86 86
 
87
-        $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString);
87
+		$this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString);
88 88
 
89
-        return $this;
90
-    }
89
+		return $this;
90
+	}
91 91
 
92
-    /**
93
-     * @return string
94
-     */
95
-    private function getInsertMultipleRowsSyntax()
96
-    {
97
-        if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class))
98
-            return $this->getSyntaxWithSelect();
92
+	/**
93
+	 * @return string
94
+	 */
95
+	private function getInsertMultipleRowsSyntax()
96
+	{
97
+		if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class))
98
+			return $this->getSyntaxWithSelect();
99 99
 
100
-        $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )';
101
-        $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', ');
100
+		$fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )';
101
+		$values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', ');
102 102
 
103
-        return $fields . ' VALUES ' . $values;
104
-    }
103
+		return $fields . ' VALUES ' . $values;
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * @return string
109
-     */
110
-    private function getSyntaxWithSelect()
111
-    {
112
-        $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )';
107
+	/**
108
+	 * @return string
109
+	 */
110
+	private function getSyntaxWithSelect()
111
+	{
112
+		$fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )';
113 113
 
114
-        return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax();
115
-    }
114
+		return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax();
115
+	}
116 116
 
117
-    /**
118
-     * @return int
119
-     */
120
-    private function getNumberOfFields()
121
-    {
122
-        return count($this->queryStructure->getElement(QueryStructure::FIELDS));
123
-    }
117
+	/**
118
+	 * @return int
119
+	 */
120
+	private function getNumberOfFields()
121
+	{
122
+		return count($this->queryStructure->getElement(QueryStructure::FIELDS));
123
+	}
124 124
 
125 125
 
126 126
 }
127 127
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/SelectFields.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@
 block discarded – undo
14 14
 
15 15
 trait SelectFields
16 16
 {
17
-    use Objects;
17
+	use Objects;
18 18
 
19 19
 
20
-    /**
21
-     * @param string|array $fields
22
-     * @return $this
23
-     * @throws QueryException
24
-     */
25
-    public function fields($fields)
26
-    {
20
+	/**
21
+	 * @param string|array $fields
22
+	 * @return $this
23
+	 * @throws QueryException
24
+	 */
25
+	public function fields($fields)
26
+	{
27 27
 
28
-        switch (gettype($fields)) {
29
-            case QueryStructure::ELEMENT_TYPE_ARRAY:
28
+		switch (gettype($fields)) {
29
+			case QueryStructure::ELEMENT_TYPE_ARRAY:
30 30
 
31
-                $fields = $this->prepareArrayFields($fields);
31
+				$fields = $this->prepareArrayFields($fields);
32 32
 
33
-                if (count($fields))
34
-                    $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else
35
-                    $this->queryStructure->setElement(QueryStructure::FIELDS, '*');
36
-                break;
33
+				if (count($fields))
34
+					$this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else
35
+					$this->queryStructure->setElement(QueryStructure::FIELDS, '*');
36
+				break;
37 37
 
38
-            case QueryStructure::ELEMENT_TYPE_STRING:
38
+			case QueryStructure::ELEMENT_TYPE_STRING:
39 39
 
40
-                $fields = trim($fields);
41
-                if ('' !== $fields)
42
-                    $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else
43
-                    $this->queryStructure->setElement(QueryStructure::FIELDS, '*');
44
-                break;
40
+				$fields = trim($fields);
41
+				if ('' !== $fields)
42
+					$this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else
43
+					$this->queryStructure->setElement(QueryStructure::FIELDS, '*');
44
+				break;
45 45
 
46
-            default:
47
-                throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY);
46
+			default:
47
+				throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY);
48 48
 
49
-        }
49
+		}
50 50
 
51
-        return $this;
52
-    }
51
+		return $this;
52
+	}
53 53
 
54
-    /**
55
-     * @param array $fieldsArray
56
-     * @return array
57
-     * @throws QueryException
58
-     */
59
-    private function prepareArrayFields($fieldsArray = array())
60
-    {
61
-        $prepareArray = [];
54
+	/**
55
+	 * @param array $fieldsArray
56
+	 * @return array
57
+	 * @throws QueryException
58
+	 */
59
+	private function prepareArrayFields($fieldsArray = array())
60
+	{
61
+		$prepareArray = [];
62 62
 
63
-        foreach ($fieldsArray as $field) {
64
-            if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING)
65
-                throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD);
63
+		foreach ($fieldsArray as $field) {
64
+			if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING)
65
+				throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD);
66 66
 
67
-            if ('' !== trim($field))
68
-                $prepareArray[] = trim($field);
69
-        }
67
+			if ('' !== trim($field))
68
+				$prepareArray[] = trim($field);
69
+		}
70 70
 
71
-        return $prepareArray;
72
-    }
71
+		return $prepareArray;
72
+	}
73 73
 
74 74
 }
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/GroupBy.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -15,68 +15,68 @@
 block discarded – undo
15 15
 trait GroupBy
16 16
 {
17 17
 
18
-    use Objects;
18
+	use Objects;
19 19
 
20 20
 
21
-    /**
22
-     * @param $column
23
-     * @param array $allowedColumns
24
-     * @return $this
25
-     * @throws QueryException
26
-     */
27
-    public function groupBy($column, array $allowedColumns = [])
28
-    {
29
-        $column = trim($column);
21
+	/**
22
+	 * @param $column
23
+	 * @param array $allowedColumns
24
+	 * @return $this
25
+	 * @throws QueryException
26
+	 */
27
+	public function groupBy($column, array $allowedColumns = [])
28
+	{
29
+		$column = trim($column);
30 30
 
31
-        if (!$this->validateColumn($column, $allowedColumns))
32
-            throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
31
+		if (!$this->validateColumn($column, $allowedColumns))
32
+			throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
33 33
 
34
-        $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column);
34
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $column);
35 35
 
36
-        return $this;
37
-    }
36
+		return $this;
37
+	}
38 38
 
39 39
 
40
-    /**
41
-     * @param $column
42
-     * @param array $allowedColumns
43
-     * @return $this
44
-     * @throws QueryException
45
-     */
46
-    public function groupByDesc($column, array $allowedColumns = [])
47
-    {
48
-        $column = trim($column);
40
+	/**
41
+	 * @param $column
42
+	 * @param array $allowedColumns
43
+	 * @return $this
44
+	 * @throws QueryException
45
+	 */
46
+	public function groupByDesc($column, array $allowedColumns = [])
47
+	{
48
+		$column = trim($column);
49 49
 
50
-        if (!$this->validateColumn($column, $allowedColumns))
51
-            throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
50
+		if (!$this->validateColumn($column, $allowedColumns))
51
+			throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME);
52 52
 
53
-        $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC');
53
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC');
54 54
 
55
-        return $this;
56
-    }
55
+		return $this;
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * @param $expression
61
-     * @return $this
62
-     */
63
-    public function groupByExpression($expression)
64
-    {
65
-        $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression);
59
+	/**
60
+	 * @param $expression
61
+	 * @return $this
62
+	 */
63
+	public function groupByExpression($expression)
64
+	{
65
+		$this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression);
66 66
 
67
-        return $this;
68
-    }
67
+		return $this;
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * @return string
73
-     */
74
-    private function getGroupBySyntax()
75
-    {
76
-        if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY)))
77
-            return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', ');
71
+	/**
72
+	 * @return string
73
+	 */
74
+	private function getGroupBySyntax()
75
+	{
76
+		if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY)))
77
+			return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', ');
78 78
 
79
-        return '';
80
-    }
79
+		return '';
80
+	}
81 81
 
82 82
 }
83 83
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/Replacement.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -16,40 +16,40 @@
 block discarded – undo
16 16
 trait Replacement
17 17
 {
18 18
 
19
-    use Objects;
20
-
21
-    /**
22
-     * @param $syntax
23
-     * @param int $withReplacement
24
-     * @return mixed|string
25
-     */
26
-    private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE)
27
-    {
28
-        $syntax = QueryHelper::clearMultipleSpaces($syntax);
29
-
30
-        if (!$withReplacement)
31
-            return $syntax;
32
-
33
-        return $this->replaceValues($syntax);
34
-    }
35
-
36
-    /**
37
-     * @param $syntax
38
-     * @return string
39
-     */
40
-    private function replaceValues($syntax)
41
-    {
42
-        $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
43
-        $search = array();
44
-        $replace = array();
45
-        foreach ($bindParams as $key => $value) {
46
-            $search[] = ':' . $key;
47
-            $replace[] = DbConnect::getInstance()->quote($value);
48
-        }
49
-        $syntax = str_ireplace($search, $replace, $syntax);
50
-
51
-        return $syntax;
52
-
53
-    }
19
+	use Objects;
20
+
21
+	/**
22
+	 * @param $syntax
23
+	 * @param int $withReplacement
24
+	 * @return mixed|string
25
+	 */
26
+	private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE)
27
+	{
28
+		$syntax = QueryHelper::clearMultipleSpaces($syntax);
29
+
30
+		if (!$withReplacement)
31
+			return $syntax;
32
+
33
+		return $this->replaceValues($syntax);
34
+	}
35
+
36
+	/**
37
+	 * @param $syntax
38
+	 * @return string
39
+	 */
40
+	private function replaceValues($syntax)
41
+	{
42
+		$bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS);
43
+		$search = array();
44
+		$replace = array();
45
+		foreach ($bindParams as $key => $value) {
46
+			$search[] = ':' . $key;
47
+			$replace[] = DbConnect::getInstance()->quote($value);
48
+		}
49
+		$syntax = str_ireplace($search, $replace, $syntax);
50
+
51
+		return $syntax;
52
+
53
+	}
54 54
 
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/Distinct.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -15,60 +15,60 @@
 block discarded – undo
15 15
 trait Distinct
16 16
 {
17 17
 
18
-    use Objects;
19
-
20
-
21
-    /**
22
-     * @return $this
23
-     */
24
-    public function all()
25
-    {
26
-        $this->queryStructure->setElement(QueryStructure::DISTINCT, 0);
27
-
28
-        return $this;
29
-    }
30
-
31
-    /**
32
-     * @return $this
33
-     */
34
-    public function distinct()
35
-    {
36
-        $this->queryStructure->setElement(QueryStructure::DISTINCT, 1);
37
-
38
-        return $this;
39
-    }
40
-
41
-    /**
42
-     * @return $this
43
-     */
44
-    public function distinctRow()
45
-    {
46
-        $this->queryStructure->setElement(QueryStructure::DISTINCT, 2);
47
-
48
-        return $this;
49
-    }
50
-
51
-
52
-    /**
53
-     * @return string
54
-     * @throws QueryException
55
-     */
56
-    private function getDistinctSyntax()
57
-    {
58
-        $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT);
59
-
60
-        switch ($useDistinct) {
61
-            case 0:
62
-                return '';
63
-            case 1:
64
-                return 'DISTINCT';
65
-            case 2:
66
-                return 'DISTINCTROW';
67
-            default:
68
-                throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT);
69
-        }
70
-
71
-    }
18
+	use Objects;
19
+
20
+
21
+	/**
22
+	 * @return $this
23
+	 */
24
+	public function all()
25
+	{
26
+		$this->queryStructure->setElement(QueryStructure::DISTINCT, 0);
27
+
28
+		return $this;
29
+	}
30
+
31
+	/**
32
+	 * @return $this
33
+	 */
34
+	public function distinct()
35
+	{
36
+		$this->queryStructure->setElement(QueryStructure::DISTINCT, 1);
37
+
38
+		return $this;
39
+	}
40
+
41
+	/**
42
+	 * @return $this
43
+	 */
44
+	public function distinctRow()
45
+	{
46
+		$this->queryStructure->setElement(QueryStructure::DISTINCT, 2);
47
+
48
+		return $this;
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return string
54
+	 * @throws QueryException
55
+	 */
56
+	private function getDistinctSyntax()
57
+	{
58
+		$useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT);
59
+
60
+		switch ($useDistinct) {
61
+			case 0:
62
+				return '';
63
+			case 1:
64
+				return 'DISTINCT';
65
+			case 2:
66
+				return 'DISTINCTROW';
67
+			default:
68
+				throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT);
69
+		}
70
+
71
+	}
72 72
 
73 73
 
74 74
 }
75 75
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/Having.php 1 patch
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -13,337 +13,337 @@
 block discarded – undo
13 13
 trait Having
14 14
 {
15 15
 
16
-    use Objects;
17
-
18
-
19
-    /**
20
-     * @param $field
21
-     * @param $value
22
-     * @param $glue
23
-     * @return $this
24
-     */
25
-    public function havingEqual($field, $value, $glue = 'AND')
26
-    {
27
-        return $this->having(array($field, $value, '='), $glue);
28
-    }
29
-
30
-    /**
31
-     * @param $field
32
-     * @param $value
33
-     * @return $this
34
-     */
35
-    public function orHavingEqual($field, $value)
36
-    {
37
-        return $this->having(array($field, $value, '='), 'OR');
38
-    }
39
-
40
-    /**
41
-     * @param $field
42
-     * @param $value
43
-     * @param string $glue
44
-     * @return $this
45
-     */
46
-    public function havingNotEqual($field, $value, $glue = 'AND')
47
-    {
48
-        return $this->having(array($field, $value, '<>'), $glue);
49
-    }
50
-
51
-    /**
52
-     * @param $field
53
-     * @param $value
54
-     * @return $this
55
-     */
56
-    public function orHavingNotEqual($field, $value)
57
-    {
58
-        return $this->having(array($field, $value, '<>'), 'OR');
59
-    }
60
-
61
-    /**
62
-     * @param $field
63
-     * @param $value
64
-     * @param string $glue
65
-     * @return $this
66
-     */
67
-    public function havingLessThan($field, $value, $glue = 'AND')
68
-    {
69
-        return $this->having(array($field, $value, '<'), $glue);
70
-    }
71
-
72
-    /**
73
-     * @param $field
74
-     * @param $value
75
-     * @return $this
76
-     */
77
-    public function orHavingLessThan($field, $value)
78
-    {
79
-        return $this->having(array($field, $value, '<'), 'OR');
80
-    }
81
-
82
-    /**
83
-     * @param $field
84
-     * @param $value
85
-     * @param string $glue
86
-     * @return $this
87
-     */
88
-    public function havingLessThanOrEqual($field, $value, $glue = 'AND')
89
-    {
90
-        return $this->having(array($field, $value, '<='), $glue);
91
-    }
92
-
93
-    /**
94
-     * @param $field
95
-     * @param $value
96
-     * @return $this
97
-     */
98
-    public function orHavingLessThanOrEqual($field, $value)
99
-    {
100
-        return $this->having(array($field, $value, '<='), 'OR');
101
-    }
102
-
103
-    /**
104
-     * @param $field
105
-     * @param $value
106
-     * @param string $glue
107
-     * @return $this
108
-     */
109
-    public function havingGreaterThan($field, $value, $glue = 'AND')
110
-    {
111
-        return $this->having(array($field, $value, '>'), $glue);
112
-    }
113
-
114
-    /**
115
-     * @param $field
116
-     * @param $value
117
-     * @return $this
118
-     */
119
-    public function orHavingGreaterThan($field, $value)
120
-    {
121
-        return $this->having(array($field, $value, '>'), 'OR');
122
-    }
123
-
124
-    /**
125
-     * @param $field
126
-     * @param $value
127
-     * @param string $glue
128
-     * @return $this
129
-     */
130
-    public function havingGreaterThanOrEqual($field, $value, $glue = 'AND')
131
-    {
132
-        return $this->having(array($field, $value, '>='), $glue);
133
-    }
134
-
135
-    /**
136
-     * @param $field
137
-     * @param $value
138
-     * @return $this
139
-     */
140
-    public function orHavingGreaterThanOrEqual($field, $value)
141
-    {
142
-        return $this->having(array($field, $value, '>='), 'OR');
143
-    }
144
-
145
-    /**
146
-     * @param $field
147
-     * @param $value
148
-     * @param string $glue
149
-     * @return $this
150
-     */
151
-    public function havingLike($field, $value, $glue = 'AND')
152
-    {
153
-        return $this->having(array($field, $value, 'LIKE'), $glue);
154
-    }
155
-
156
-    /**
157
-     * @param $field
158
-     * @param $value
159
-     * @return $this
160
-     */
161
-    public function orHavingLike($field, $value)
162
-    {
163
-        return $this->having(array($field, $value, 'LIKE'), 'OR');
164
-    }
165
-
166
-    /**
167
-     * @param $field
168
-     * @param $value
169
-     * @param string $glue
170
-     * @return $this
171
-     */
172
-    public function havingNotLike($field, $value, $glue = 'AND')
173
-    {
174
-        return $this->having(array($field, $value, 'NOT LIKE'), $glue);
175
-    }
176
-
177
-    /**
178
-     * @param $field
179
-     * @param $value
180
-     * @return $this
181
-     */
182
-    public function orHavingNotLike($field, $value)
183
-    {
184
-        return $this->having(array($field, $value, 'NOT LIKE'), 'OR');
185
-    }
186
-
187
-    /**
188
-     * @param $field
189
-     * @param $min
190
-     * @param $max
191
-     * @param string $glue
192
-     * @return $this
193
-     */
194
-    public function havingBetween($field, $min, $max, $glue = 'AND')
195
-    {
196
-        return $this->having(array($field, array($min, $max), 'BETWEEN'), $glue);
197
-    }
198
-
199
-    /**
200
-     * @param $field
201
-     * @param $min
202
-     * @param $max
203
-     * @return $this
204
-     */
205
-    public function orHavingBetween($field, $min, $max)
206
-    {
207
-        return $this->having(array($field, array($min, $max), 'BETWEEN'), 'OR');
208
-    }
209
-
210
-    /**
211
-     * @param $field
212
-     * @param $min
213
-     * @param $max
214
-     * @param string $glue
215
-     * @return $this
216
-     */
217
-    public function havingNotBetween($field, $min, $max, $glue = 'AND')
218
-    {
219
-        return $this->having(array($field, array($min, $max), 'NOT BETWEEN'), $glue);
220
-    }
221
-
222
-    /**
223
-     * @param $field
224
-     * @param $min
225
-     * @param $max
226
-     * @return $this
227
-     */
228
-    public function orHavingNotBetween($field, $min, $max)
229
-    {
230
-        return $this->having(array($field, array($min, $max), 'NOT BETWEEN'), 'OR');
231
-    }
232
-
233
-    /**
234
-     * @param $field
235
-     * @param $value
236
-     * @param string $glue
237
-     * @return $this
238
-     */
239
-    public function havingIn($field, $value, $glue = 'AND')
240
-    {
241
-        return $this->having(array($field, $value, 'IN'), $glue);
242
-    }
243
-
244
-    /**
245
-     * @param $field
246
-     * @param $value
247
-     * @return $this
248
-     */
249
-    public function orHavingIn($field, $value)
250
-    {
251
-        return $this->having(array($field, $value, 'IN'), 'OR');
252
-    }
253
-
254
-    /**
255
-     * @param $field
256
-     * @param $value
257
-     * @param string $glue
258
-     * @return $this
259
-     */
260
-    public function havingNotIn($field, $value, $glue = 'AND')
261
-    {
262
-        return $this->having(array($field, $value, 'NOT IN'), $glue);
263
-    }
264
-
265
-    /**
266
-     * @param $field
267
-     * @param $value
268
-     * @return $this
269
-     */
270
-    public function orHavingNotIn($field, $value)
271
-    {
272
-        return $this->having(array($field, $value, 'NOT IN'), 'OR');
273
-    }
274
-
275
-    /**
276
-     * @param $whereString
277
-     * @param array $bindParams
278
-     * @param string $glue
279
-     * @return $this
280
-     */
281
-    public function havingExpression($whereString, array $bindParams = [], $glue = 'AND')
282
-    {
283
-        $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams);
284
-
285
-        return $this->having($whereString, $glue);
286
-    }
287
-
288
-    /**
289
-     * @param $whereString
290
-     * @param array $bindParams
291
-     * @return $this
292
-     */
293
-    public function orHavingExpression($whereString, array $bindParams = [])
294
-    {
295
-        $whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams);
296
-
297
-        return $this->having($whereString, 'OR');
298
-    }
299
-
300
-    /**
301
-     * @return $this
302
-     */
303
-    public function havingInvertResult()
304
-    {
305
-        $this->queryStructure->setElement(QueryStructure::HAVING_INVERT, 1);
306
-
307
-        return $this;
308
-    }
309
-
310
-    /**
311
-     * @param string $glue
312
-     * @return $this
313
-     */
314
-    public function havingGroup($glue = 'AND')
315
-    {
316
-        $this->queryStructure->setElement(QueryStructure::HAVING, array('glue' => $glue, 'body' => '(', 'type' => 'start_where_group'));
317
-
318
-        return $this;
319
-    }
320
-
321
-    /**
322
-     * @return $this
323
-     */
324
-    public function orHavingGroup()
325
-    {
326
-        return $this->havingGroup('OR');
327
-    }
328
-
329
-    /**
330
-     * @return $this
331
-     */
332
-    public function havingGroupEnd()
333
-    {
334
-        $this->queryStructure->setElement(QueryStructure::HAVING, array('glue' => '', 'body' => ')', 'type' => 'end_where_group'));
335
-
336
-        return $this;
337
-    }
338
-
339
-    /**
340
-     * @param $param
341
-     * @param string $glue
342
-     * @return $this
343
-     */
344
-    private function having($param, $glue = 'AND')
345
-    {
346
-        return $this->createCondition($param, $glue, QueryStructure::HAVING);
347
-    }
16
+	use Objects;
17
+
18
+
19
+	/**
20
+	 * @param $field
21
+	 * @param $value
22
+	 * @param $glue
23
+	 * @return $this
24
+	 */
25
+	public function havingEqual($field, $value, $glue = 'AND')
26
+	{
27
+		return $this->having(array($field, $value, '='), $glue);
28
+	}
29
+
30
+	/**
31
+	 * @param $field
32
+	 * @param $value
33
+	 * @return $this
34
+	 */
35
+	public function orHavingEqual($field, $value)
36
+	{
37
+		return $this->having(array($field, $value, '='), 'OR');
38
+	}
39
+
40
+	/**
41
+	 * @param $field
42
+	 * @param $value
43
+	 * @param string $glue
44
+	 * @return $this
45
+	 */
46
+	public function havingNotEqual($field, $value, $glue = 'AND')
47
+	{
48
+		return $this->having(array($field, $value, '<>'), $glue);
49
+	}
50
+
51
+	/**
52
+	 * @param $field
53
+	 * @param $value
54
+	 * @return $this
55
+	 */
56
+	public function orHavingNotEqual($field, $value)
57
+	{
58
+		return $this->having(array($field, $value, '<>'), 'OR');
59
+	}
60
+
61
+	/**
62
+	 * @param $field
63
+	 * @param $value
64
+	 * @param string $glue
65
+	 * @return $this
66
+	 */
67
+	public function havingLessThan($field, $value, $glue = 'AND')
68
+	{
69
+		return $this->having(array($field, $value, '<'), $glue);
70
+	}
71
+
72
+	/**
73
+	 * @param $field
74
+	 * @param $value
75
+	 * @return $this
76
+	 */
77
+	public function orHavingLessThan($field, $value)
78
+	{
79
+		return $this->having(array($field, $value, '<'), 'OR');
80
+	}
81
+
82
+	/**
83
+	 * @param $field
84
+	 * @param $value
85
+	 * @param string $glue
86
+	 * @return $this
87
+	 */
88
+	public function havingLessThanOrEqual($field, $value, $glue = 'AND')
89
+	{
90
+		return $this->having(array($field, $value, '<='), $glue);
91
+	}
92
+
93
+	/**
94
+	 * @param $field
95
+	 * @param $value
96
+	 * @return $this
97
+	 */
98
+	public function orHavingLessThanOrEqual($field, $value)
99
+	{
100
+		return $this->having(array($field, $value, '<='), 'OR');
101
+	}
102
+
103
+	/**
104
+	 * @param $field
105
+	 * @param $value
106
+	 * @param string $glue
107
+	 * @return $this
108
+	 */
109
+	public function havingGreaterThan($field, $value, $glue = 'AND')
110
+	{
111
+		return $this->having(array($field, $value, '>'), $glue);
112
+	}
113
+
114
+	/**
115
+	 * @param $field
116
+	 * @param $value
117
+	 * @return $this
118
+	 */
119
+	public function orHavingGreaterThan($field, $value)
120
+	{
121
+		return $this->having(array($field, $value, '>'), 'OR');
122
+	}
123
+
124
+	/**
125
+	 * @param $field
126
+	 * @param $value
127
+	 * @param string $glue
128
+	 * @return $this
129
+	 */
130
+	public function havingGreaterThanOrEqual($field, $value, $glue = 'AND')
131
+	{
132
+		return $this->having(array($field, $value, '>='), $glue);
133
+	}
134
+
135
+	/**
136
+	 * @param $field
137
+	 * @param $value
138
+	 * @return $this
139
+	 */
140
+	public function orHavingGreaterThanOrEqual($field, $value)
141
+	{
142
+		return $this->having(array($field, $value, '>='), 'OR');
143
+	}
144
+
145
+	/**
146
+	 * @param $field
147
+	 * @param $value
148
+	 * @param string $glue
149
+	 * @return $this
150
+	 */
151
+	public function havingLike($field, $value, $glue = 'AND')
152
+	{
153
+		return $this->having(array($field, $value, 'LIKE'), $glue);
154
+	}
155
+
156
+	/**
157
+	 * @param $field
158
+	 * @param $value
159
+	 * @return $this
160
+	 */
161
+	public function orHavingLike($field, $value)
162
+	{
163
+		return $this->having(array($field, $value, 'LIKE'), 'OR');
164
+	}
165
+
166
+	/**
167
+	 * @param $field
168
+	 * @param $value
169
+	 * @param string $glue
170
+	 * @return $this
171
+	 */
172
+	public function havingNotLike($field, $value, $glue = 'AND')
173
+	{
174
+		return $this->having(array($field, $value, 'NOT LIKE'), $glue);
175
+	}
176
+
177
+	/**
178
+	 * @param $field
179
+	 * @param $value
180
+	 * @return $this
181
+	 */
182
+	public function orHavingNotLike($field, $value)
183
+	{
184
+		return $this->having(array($field, $value, 'NOT LIKE'), 'OR');
185
+	}
186
+
187
+	/**
188
+	 * @param $field
189
+	 * @param $min
190
+	 * @param $max
191
+	 * @param string $glue
192
+	 * @return $this
193
+	 */
194
+	public function havingBetween($field, $min, $max, $glue = 'AND')
195
+	{
196
+		return $this->having(array($field, array($min, $max), 'BETWEEN'), $glue);
197
+	}
198
+
199
+	/**
200
+	 * @param $field
201
+	 * @param $min
202
+	 * @param $max
203
+	 * @return $this
204
+	 */
205
+	public function orHavingBetween($field, $min, $max)
206
+	{
207
+		return $this->having(array($field, array($min, $max), 'BETWEEN'), 'OR');
208
+	}
209
+
210
+	/**
211
+	 * @param $field
212
+	 * @param $min
213
+	 * @param $max
214
+	 * @param string $glue
215
+	 * @return $this
216
+	 */
217
+	public function havingNotBetween($field, $min, $max, $glue = 'AND')
218
+	{
219
+		return $this->having(array($field, array($min, $max), 'NOT BETWEEN'), $glue);
220
+	}
221
+
222
+	/**
223
+	 * @param $field
224
+	 * @param $min
225
+	 * @param $max
226
+	 * @return $this
227
+	 */
228
+	public function orHavingNotBetween($field, $min, $max)
229
+	{
230
+		return $this->having(array($field, array($min, $max), 'NOT BETWEEN'), 'OR');
231
+	}
232
+
233
+	/**
234
+	 * @param $field
235
+	 * @param $value
236
+	 * @param string $glue
237
+	 * @return $this
238
+	 */
239
+	public function havingIn($field, $value, $glue = 'AND')
240
+	{
241
+		return $this->having(array($field, $value, 'IN'), $glue);
242
+	}
243
+
244
+	/**
245
+	 * @param $field
246
+	 * @param $value
247
+	 * @return $this
248
+	 */
249
+	public function orHavingIn($field, $value)
250
+	{
251
+		return $this->having(array($field, $value, 'IN'), 'OR');
252
+	}
253
+
254
+	/**
255
+	 * @param $field
256
+	 * @param $value
257
+	 * @param string $glue
258
+	 * @return $this
259
+	 */
260
+	public function havingNotIn($field, $value, $glue = 'AND')
261
+	{
262
+		return $this->having(array($field, $value, 'NOT IN'), $glue);
263
+	}
264
+
265
+	/**
266
+	 * @param $field
267
+	 * @param $value
268
+	 * @return $this
269
+	 */
270
+	public function orHavingNotIn($field, $value)
271
+	{
272
+		return $this->having(array($field, $value, 'NOT IN'), 'OR');
273
+	}
274
+
275
+	/**
276
+	 * @param $whereString
277
+	 * @param array $bindParams
278
+	 * @param string $glue
279
+	 * @return $this
280
+	 */
281
+	public function havingExpression($whereString, array $bindParams = [], $glue = 'AND')
282
+	{
283
+		$whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams);
284
+
285
+		return $this->having($whereString, $glue);
286
+	}
287
+
288
+	/**
289
+	 * @param $whereString
290
+	 * @param array $bindParams
291
+	 * @return $this
292
+	 */
293
+	public function orHavingExpression($whereString, array $bindParams = [])
294
+	{
295
+		$whereString = $this->queryStructure->bindParamsExpression($whereString, $bindParams);
296
+
297
+		return $this->having($whereString, 'OR');
298
+	}
299
+
300
+	/**
301
+	 * @return $this
302
+	 */
303
+	public function havingInvertResult()
304
+	{
305
+		$this->queryStructure->setElement(QueryStructure::HAVING_INVERT, 1);
306
+
307
+		return $this;
308
+	}
309
+
310
+	/**
311
+	 * @param string $glue
312
+	 * @return $this
313
+	 */
314
+	public function havingGroup($glue = 'AND')
315
+	{
316
+		$this->queryStructure->setElement(QueryStructure::HAVING, array('glue' => $glue, 'body' => '(', 'type' => 'start_where_group'));
317
+
318
+		return $this;
319
+	}
320
+
321
+	/**
322
+	 * @return $this
323
+	 */
324
+	public function orHavingGroup()
325
+	{
326
+		return $this->havingGroup('OR');
327
+	}
328
+
329
+	/**
330
+	 * @return $this
331
+	 */
332
+	public function havingGroupEnd()
333
+	{
334
+		$this->queryStructure->setElement(QueryStructure::HAVING, array('glue' => '', 'body' => ')', 'type' => 'end_where_group'));
335
+
336
+		return $this;
337
+	}
338
+
339
+	/**
340
+	 * @param $param
341
+	 * @param string $glue
342
+	 * @return $this
343
+	 */
344
+	private function having($param, $glue = 'AND')
345
+	{
346
+		return $this->createCondition($param, $glue, QueryStructure::HAVING);
347
+	}
348 348
 
349 349
 }
350 350
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/WhereAndHavingBuilder.php 1 patch
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -17,167 +17,167 @@
 block discarded – undo
17 17
 trait WhereAndHavingBuilder
18 18
 {
19 19
 
20
-    use Objects;
21
-
22
-
23
-    /**
24
-     * @param $param
25
-     * @param string $glue
26
-     * @param $clauseType
27
-     * @return $this
28
-     */
29
-    protected function createCondition($param, $glue = 'AND', $clauseType)
30
-    {
31
-
32
-        if (!is_array($param)) {
33
-            $this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => trim($param), 'type' => 'cond'));
34
-
35
-            return $this;
36
-        }
37
-
38
-        $param = $this->validateWhereParam($param);
39
-
40
-        $field = $param[0];
41
-        $value = $param[1];
42
-        $operator = $param[2];
43
-
44
-        switch ($operator) {
45
-            case 'BETWEEN':
46
-            case 'NOT BETWEEN':
47
-            case '!BETWEEN':
48
-                $min = $value[0];
49
-                $max = $value[1];
50
-                $body = [$field, $operator, $this->queryStructure->bindParam('min', $min), 'AND', $this->queryStructure->bindParam('max', $max)];
51
-                $body = implode(' ', $body);
52
-                $this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
53
-                break;
54
-
55
-            case 'IN':
56
-            case 'NOT IN':
57
-            case '!IN':
58
-                if (is_a($value, QuerySelect::class))
59
-                    return $this->inSelectObject($field, $value, $operator, $glue, $clauseType); elseif (is_array($value))
60
-                    return $this->inArray($field, $value, $operator, $glue, $clauseType);
61
-                break;
62
-
63
-            default:
64
-                $valuePdoString = $this->queryStructure->bindParam($field, $value);
65
-                $body = $field . ' ' . $operator . ' ' . $valuePdoString;
66
-                $this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
67
-
68
-        }
69
-
70
-        return $this;
71
-
72
-    }
73
-
74
-
75
-    /**
76
-     * @param $field
77
-     * @param QuerySelect $subquerySelect
78
-     * @param $operator
79
-     * @param string $glue
80
-     * @param $clauseType
81
-     * @return $this
82
-     */
83
-    private function inSelectObject($field, QuerySelect $subquerySelect, $operator, $glue = 'AND', $clauseType)
84
-    {
85
-        $subquerySelectParams = $subquerySelect->getBindParams();
86
-        foreach ($subquerySelectParams as $key => $value) {
87
-            $this->queryStructure->setParams($key, $value);
88
-        }
89
-        $body = [$field, $operator, '( ', $subquerySelect->getSyntax(), ' )'];
90
-        $body = implode(' ', $body);
91
-        $this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
92
-
93
-        return $this;
94
-    }
95
-
96
-    /**
97
-     * @param $field
98
-     * @param array $value
99
-     * @param $operator
100
-     * @param $glue
101
-     * @param $clauseType
102
-     * @return $this
103
-     */
104
-    private function inArray($field, array $value, $operator, $glue, $clauseType)
105
-    {
106
-        $pdoArray = array();
107
-        foreach ($value as $item) {
108
-            $pdoArray[] = $this->queryStructure->bindParam('a', $item);
109
-        }
110
-        $body = [$field, $operator, '( ' . implode(', ', $pdoArray) . ' )'];
111
-        $body = implode(' ', $body);
112
-        $body = QueryHelper::clearMultipleSpaces($body);
113
-        $this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
114
-
115
-        return $this;
116
-    }
117
-
118
-
119
-    /**
120
-     * @return bool|mixed|string
121
-     */
122
-    private function getWhereSyntax()
123
-    {
124
-        return $this->getWhereAndHavingSyntax(QueryStructure::WHERE);
125
-    }
126
-
127
-    /**
128
-     * @return bool|mixed|string
129
-     */
130
-    private function getHavingSyntax()
131
-    {
132
-        return $this->getWhereAndHavingSyntax(QueryStructure::HAVING);
133
-    }
134
-
135
-    /**
136
-     * @param $clauseType
137
-     * @return bool|mixed|string
138
-     */
139
-    private function getWhereAndHavingSyntax($clauseType)
140
-    {
141
-        if (count($this->queryStructure->getElement($clauseType)) == 0)
142
-            return '';
143
-
144
-        $where = '';
145
-        $last_type = 'where_start';
146
-        foreach ($this->queryStructure->getElement($clauseType) as $where_cond) {
147
-            $glue = $where_cond['glue'];
148
-            if ($last_type == 'where_start' || $last_type == 'start_where_group') {
149
-                $glue = '';
150
-            }
151
-            $where .= ' ' . $glue . ' ' . $where_cond['body'];
152
-            $last_type = $where_cond['type'];
153
-        }
154
-
155
-        if ($this->queryStructure->getElement($clauseType . '_invert')) {
156
-            $where = ' NOT ( ' . $where . ' ) ';
157
-        }
158
-
159
-        $where = 'WHERE ' . $where;
160
-
161
-        return QueryHelper::clearMultipleSpaces($where);
162
-    }
163
-
164
-    /**
165
-     * @param $param
166
-     * @return array
167
-     * @throws QueryException
168
-     */
169
-    private function validateWhereParam($param)
170
-    {
171
-        if (count($param) < 2)
172
-            throw new QueryException('Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY);
173
-
174
-        if (count($param) == 2)
175
-            $param[] = '=';
176
-
177
-        $param[2] = trim(strtoupper($param[2]));
178
-        $param[2] = QueryHelper::clearMultipleSpaces($param[2]);
179
-
180
-        return $param;
181
-    }
20
+	use Objects;
21
+
22
+
23
+	/**
24
+	 * @param $param
25
+	 * @param string $glue
26
+	 * @param $clauseType
27
+	 * @return $this
28
+	 */
29
+	protected function createCondition($param, $glue = 'AND', $clauseType)
30
+	{
31
+
32
+		if (!is_array($param)) {
33
+			$this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => trim($param), 'type' => 'cond'));
34
+
35
+			return $this;
36
+		}
37
+
38
+		$param = $this->validateWhereParam($param);
39
+
40
+		$field = $param[0];
41
+		$value = $param[1];
42
+		$operator = $param[2];
43
+
44
+		switch ($operator) {
45
+			case 'BETWEEN':
46
+			case 'NOT BETWEEN':
47
+			case '!BETWEEN':
48
+				$min = $value[0];
49
+				$max = $value[1];
50
+				$body = [$field, $operator, $this->queryStructure->bindParam('min', $min), 'AND', $this->queryStructure->bindParam('max', $max)];
51
+				$body = implode(' ', $body);
52
+				$this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
53
+				break;
54
+
55
+			case 'IN':
56
+			case 'NOT IN':
57
+			case '!IN':
58
+				if (is_a($value, QuerySelect::class))
59
+					return $this->inSelectObject($field, $value, $operator, $glue, $clauseType); elseif (is_array($value))
60
+					return $this->inArray($field, $value, $operator, $glue, $clauseType);
61
+				break;
62
+
63
+			default:
64
+				$valuePdoString = $this->queryStructure->bindParam($field, $value);
65
+				$body = $field . ' ' . $operator . ' ' . $valuePdoString;
66
+				$this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
67
+
68
+		}
69
+
70
+		return $this;
71
+
72
+	}
73
+
74
+
75
+	/**
76
+	 * @param $field
77
+	 * @param QuerySelect $subquerySelect
78
+	 * @param $operator
79
+	 * @param string $glue
80
+	 * @param $clauseType
81
+	 * @return $this
82
+	 */
83
+	private function inSelectObject($field, QuerySelect $subquerySelect, $operator, $glue = 'AND', $clauseType)
84
+	{
85
+		$subquerySelectParams = $subquerySelect->getBindParams();
86
+		foreach ($subquerySelectParams as $key => $value) {
87
+			$this->queryStructure->setParams($key, $value);
88
+		}
89
+		$body = [$field, $operator, '( ', $subquerySelect->getSyntax(), ' )'];
90
+		$body = implode(' ', $body);
91
+		$this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
92
+
93
+		return $this;
94
+	}
95
+
96
+	/**
97
+	 * @param $field
98
+	 * @param array $value
99
+	 * @param $operator
100
+	 * @param $glue
101
+	 * @param $clauseType
102
+	 * @return $this
103
+	 */
104
+	private function inArray($field, array $value, $operator, $glue, $clauseType)
105
+	{
106
+		$pdoArray = array();
107
+		foreach ($value as $item) {
108
+			$pdoArray[] = $this->queryStructure->bindParam('a', $item);
109
+		}
110
+		$body = [$field, $operator, '( ' . implode(', ', $pdoArray) . ' )'];
111
+		$body = implode(' ', $body);
112
+		$body = QueryHelper::clearMultipleSpaces($body);
113
+		$this->queryStructure->setElement($clauseType, array('glue' => $glue, 'body' => $body, 'type' => 'cond'));
114
+
115
+		return $this;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @return bool|mixed|string
121
+	 */
122
+	private function getWhereSyntax()
123
+	{
124
+		return $this->getWhereAndHavingSyntax(QueryStructure::WHERE);
125
+	}
126
+
127
+	/**
128
+	 * @return bool|mixed|string
129
+	 */
130
+	private function getHavingSyntax()
131
+	{
132
+		return $this->getWhereAndHavingSyntax(QueryStructure::HAVING);
133
+	}
134
+
135
+	/**
136
+	 * @param $clauseType
137
+	 * @return bool|mixed|string
138
+	 */
139
+	private function getWhereAndHavingSyntax($clauseType)
140
+	{
141
+		if (count($this->queryStructure->getElement($clauseType)) == 0)
142
+			return '';
143
+
144
+		$where = '';
145
+		$last_type = 'where_start';
146
+		foreach ($this->queryStructure->getElement($clauseType) as $where_cond) {
147
+			$glue = $where_cond['glue'];
148
+			if ($last_type == 'where_start' || $last_type == 'start_where_group') {
149
+				$glue = '';
150
+			}
151
+			$where .= ' ' . $glue . ' ' . $where_cond['body'];
152
+			$last_type = $where_cond['type'];
153
+		}
154
+
155
+		if ($this->queryStructure->getElement($clauseType . '_invert')) {
156
+			$where = ' NOT ( ' . $where . ' ) ';
157
+		}
158
+
159
+		$where = 'WHERE ' . $where;
160
+
161
+		return QueryHelper::clearMultipleSpaces($where);
162
+	}
163
+
164
+	/**
165
+	 * @param $param
166
+	 * @return array
167
+	 * @throws QueryException
168
+	 */
169
+	private function validateWhereParam($param)
170
+	{
171
+		if (count($param) < 2)
172
+			throw new QueryException('Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY);
173
+
174
+		if (count($param) == 2)
175
+			$param[] = '=';
176
+
177
+		$param[2] = trim(strtoupper($param[2]));
178
+		$param[2] = QueryHelper::clearMultipleSpaces($param[2]);
179
+
180
+		return $param;
181
+	}
182 182
 
183 183
 }
184 184
\ No newline at end of file
Please login to merge, or discard this patch.
src/Traits/LowPriority.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
 trait LowPriority
15 15
 {
16 16
 
17
-    use Objects;
17
+	use Objects;
18 18
 
19
-    /**
20
-     * @return $this
21
-     */
22
-    public function lowPriority()
23
-    {
24
-        $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY');
19
+	/**
20
+	 * @return $this
21
+	 */
22
+	public function lowPriority()
23
+	{
24
+		$this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY');
25 25
 
26
-        return $this;
27
-    }
26
+		return $this;
27
+	}
28 28
 
29 29
 }
30 30
\ No newline at end of file
Please login to merge, or discard this patch.