Code Duplication    Length = 100-102 lines in 2 locations

src/Query/Traits/Clause/GroupTrait.php 1 location

@@ 29-130 (lines=102) @@
26
 * @version 2.0.0
27
 * @since   2.0.0 added
28
 */
29
trait GroupTrait
30
{
31
    use AbstractTrait;
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function group($col)
37
    {
38
        // support multiple group by
39
        if (func_num_args() > 1) {
40
            $col = func_get_args();
41
        }
42
        return $this->realGroup($col);
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function groupDesc($col)
49
    {
50
        // support multiple group by
51
        if (func_num_args() > 1) {
52
            $col = func_get_args();
53
        }
54
        return $this->realGroup($col, 'DESC');
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function groupTpl(/*# string */ $template, $col, array $params = [])
61
    {
62
        $template = $this->positionedParam($template, $params);
63
        return $this->realGroup(new Template($template, $col), '', true);
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69
    public function groupRaw(/*# string */ $rawString, array $params = [])
70
    {
71
        $rawString = $this->positionedParam($rawString, $params);
72
        return $this->realGroup($rawString, '', true);
73
    }
74
75
    /**
76
     * real group by
77
     * @param  string|string[]|Template $col column[s]
78
     * @param  string $suffix ''|ASC|DESC
79
     * @param  bool $rawMode
80
     * @return $this
81
     * @access protected
82
     */
83
    protected function realGroup(
84
        $col,
85
        /*# sting */ $suffix = '',
86
        /*# bool */ $rawMode = false
87
    ) {
88
89
        if (is_array($col)) {
90
            $this->multipleGroup($col, $suffix);
91
        } else {
92
            $clause = &$this->getClause('GROUP BY');
93
            $part = [$col, $this->isRaw($col, $rawMode)];
94
            if (!empty($suffix)) {
95
                $part[] = $suffix;
96
            }
97
            $clause[] = $part;
98
        }
99
        return $this;
100
    }
101
102
    /**
103
     * Multitple groupbys
104
     *
105
     * @param  array $cols
106
     * @param  string $suffix
107
     * @access protected
108
     */
109
    protected function multipleGroup(array $cols, /*# string */ $suffix)
110
    {
111
        foreach ($cols as $col) {
112
            $this->realGroup($col, $suffix);
113
        }
114
    }
115
116
    /**
117
     * Build GROUP BY
118
     *
119
     * @param  string $prefix
120
     * @param  array $settings
121
     * @return string
122
     * @access protected
123
     */
124
    protected function buildGroup(
125
        /*# string */ $prefix,
126
        array $settings
127
    )/*# : string */ {
128
        return $this->buildClause('GROUP BY', $prefix, $settings);
129
    }
130
}
131

src/Query/Traits/Clause/OrderTrait.php 1 location

@@ 31-130 (lines=100) @@
28
 * @version 2.0.0
29
 * @since   2.0.0 added
30
 */
31
trait OrderTrait
32
{
33
    use AbstractTrait;
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function order($col)
39
    {
40
        if (func_num_args() > 1) {
41
            $col = func_get_args();
42
        }
43
        return $this->realOrder($col, 'ASC');
44
    }
45
46
    /**
47
     * {@inheritDoc}
48
     */
49
    public function orderDesc($col)
50
    {
51
        if (func_num_args() > 1) {
52
            $col = func_get_args();
53
        }
54
        return $this->realOrder($col, 'DESC');
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function orderTpl(/*# string */ $template, $col, array $params = [])
61
    {
62
        $template = $this->positionedParam($template, $params);
63
        return $this->realOrder(new Template($template, $col), '', true);
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69
    public function orderRaw(/*# string */ $rawString, array $params = [])
70
    {
71
        $rawString = $this->positionedParam($rawString, $params);
72
        return $this->realOrder($rawString, '', true);
73
    }
74
75
    /**
76
     * Real orderby
77
     *
78
     * @param  string|string[]|Template $col
79
     * @param  string $suffix 'ASC' or 'DESC'
80
     * @param  bool $rawMode
81
     * @return $this
82
     * @access protected
83
     */
84
    protected function realOrder(
85
        $col,
86
        /*# sting */ $suffix = 'ASC',
87
        /*# bool */ $rawMode = false
88
    ) {
89
        if (is_array($col)) {
90
            $this->multipleOrder($col, $suffix);
91
        } else {
92
            $clause = &$this->getClause('ORDER BY');
93
            $part = [$col, $this->isRaw($col, $rawMode)];
94
            if (!empty($suffix)) {
95
                $part[] = $suffix;
96
            }
97
            $clause[] = $part;
98
        }
99
        return $this;
100
    }
101
102
    /**
103
     * Multitple orderbys
104
     *
105
     * @param  array $cols
106
     * @param  string $suffix 'ASC' or 'DESC'
107
     * @access protected
108
     */
109
    protected function multipleOrder(array $cols, /*# sting */ $suffix)
110
    {
111
        foreach ($cols as $col) {
112
            $this->realOrder($col, $suffix);
113
        }
114
    }
115
116
    /**
117
     * Build ORDER BY
118
     *
119
     * @param  string $prefix
120
     * @param  array $settings
121
     * @return string
122
     * @access protected
123
     */
124
    protected function buildOrder(
125
        /*# string */ $prefix,
126
        array $settings
127
    )/*# : string */ {
128
        return $this->buildClause('ORDER BY', $prefix, $settings);
129
    }
130
}
131