GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 083d1a...28e483 )
by cao
03:15
created

HavingRule   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
wmc 1
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A having() 0 4 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace PhpBoot\DB\rules\select;
3
use PhpBoot\DB\rules\basic\BasicRule;
4
use PhpBoot\DB\impls\ExecImpl;
5
use PhpBoot\DB\impls\SelectImpl;
6
use PhpBoot\DB\impls\FromImpl;
7
use PhpBoot\DB\impls\JoinImpl;
8
use PhpBoot\DB\impls\JoinOnImpl;
9
use PhpBoot\DB\impls\WhereImpl;
10
use PhpBoot\DB\impls\GroupByImpl;
11
use PhpBoot\DB\impls\OrderByImpl;
12
use PhpBoot\DB\impls\LimitImpl;
13
use PhpBoot\DB\impls\ForUpdateOfImpl;
14
use PhpBoot\DB\impls\ForUpdateImpl;
15
16 1
require_once dirname(__DIR__).'/impls.php';
17 1
require_once __DIR__.'/basic.php';
18
19
class SelectRule extends BasicRule
20
{
21
    /**
22
     * select('column0, column1') => "SELECT column0, column1"
23
     * select('column0', 'column1') => "SELECT column0, column1"
24
     * @param string $columns
25
     * @return \PhpBoot\DB\rules\select\FromRule
26
     */
27 20
    public function select($columns) {
28 20
        SelectImpl::select($this->context, $columns);
29 20
        return new FromRule($this->context);
30
    }
31
}
32
33
class GetRule extends BasicRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
34
{
35
    /**
36
     * Execute sql and get responses
37
     * @param string|false $asDict
38
     * @return array
39
     */
40 19
    public function get($asDict=false) {
41 19
        return ExecImpl::get($this->context, $asDict);
0 ignored issues
show
Bug introduced by
It seems like $asDict defined by parameter $asDict on line 40 can also be of type string; however, PhpBoot\DB\impls\ExecImpl::get() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
42
    }
43
44
    /**
45
     * @return int|false
46
     */
47
    public function count() {
48
        return ExecImpl::count($this->context);
49
    }
50
    /**
51
     * Execute sql and get one response
52
     * @return null
53
     */
54 1
    public function getFirst(){
55 1
        $res = ExecImpl::get($this->context);
56 1
        if(count($res)){
57 1
            return $res[0];
58
        }
59
        return null;
60
    }
61
}
62
class FromRule extends GetRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
63
{
64
    /**
65
     * from('table') => "FROM table"
66
     * @param string $table
67
     * @return \PhpBoot\DB\rules\select\JoinRule
68
     */
69 19
    public function from($table, $as=null){
70 19
        FromImpl::from($this->context, $table,$as);
71 19
        return new JoinRule($this->context);
72
    }
73
}
74
class ForUpdateOfRule extends GetRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
75
{
76
    /**
77
     * forUpdate()->of('column') => 'FOR UPDATE OF column'
78
     * @param string $column
79
     * @return \PhpBoot\DB\rules\select\GetRule
80
     */
81 1
    public function of($column){
82 1
        ForUpdateOfImpl::of($this->context, $column);
83 1
        return new GetRule($this->context);
84
    }
85
}
86
class ForUpdateRule extends GetRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
87
{
88
    /**
89
     * forUpdate() => 'FOR UPDATE'
90
     * @return \PhpBoot\DB\rules\select\ForUpdateOfRule
91
     */
92 2
    public function forUpdate(){
93 2
        ForUpdateImpl::forUpdate($this->context);
94 2
        return new ForUpdateOfRule($this->context);
95
    }
96
}
97
98
class LimitRule extends ForUpdateRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
99
{
100
    /**
101
     * limit(0,1) => "LIMIT 0,1"
102
     * @param int $start
103
     * @param int $size
104
     * @return \PhpBoot\DB\rules\select\ForUpdateRule
105
     */
106 1
    public function limit($start, $size) {
107 1
        LimitImpl::limitWithOffset($this->context, $start, $size);
108 1
        return new ForUpdateRule($this->context);
109
    }
110
}
111
112
class OrderByRule extends LimitRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
113
{
114 19
    public function __construct($context){
115 19
        parent::__construct($context);
116 19
        $this->order = new OrderByImpl();
117 19
    }
118
    /**
119
     * orderBy('column') => "ORDER BY column"
120
     * orderBy('column', Sql::ORDER_BY_ASC) => "ORDER BY column ASC"
121
     * orderBy('column0')->orderBy('column1') => "ORDER BY column0, column1"
122
     *
123
     * orderBy(['column0', 'column1'=>Sql::ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
124
     *
125
     * @param string $column
126
     * @param string $order Sql::ORDER_BY_ASC or Sql::ORDER_BY_DESC
127
     * @return \PhpBoot\DB\rules\select\OrderByRule
128
     */
129 3
    public function orderBy($column, $order=null) {
130 3
        $this->order->orderBy($this->context, $column, $order);
131 3
        return $this;
132
    }
133
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
//     * orderByArgs(['column0', 'column1'=>Sql::ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
135
//     * @param array $args
136
//     * @return \PhpBoot\DB\rules\select\OrderByRule
137
//     */
138
//    public function orderByArgs($args) {
139
//        $this->order->orderByArgs($this->context, $args);
140
//        return $this;
141
//    }
142
    /**
143
     * @var OrderByImpl
144
     */
145
    private $order;
146
}
147
148
class HavingRule extends OrderByRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
149
{
150
    /**
151
     *
152
     * having('SUM(a)=?', 1) => "HAVING SUM(a)=1"
153
     * having('a>?', Sql::raw('now()')) => "HAVING a>now()"
154
     * having('a IN (?)',  [1, 2]) => "HAVING a IN (1,2)"
155
     *
156
     * having([
157
     *      'a'=>1,
158
     *      'b'=>['IN'=>[1,2]]
159
     *      'c'=>['BETWEEN'=>[1,2]]
160
     *      'd'=>['<>'=>1]
161
     *      ])
162
     *
163
     *      =>
164
     *      "HAVING a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
165
     *
166
     * @param string|array $expr
167
     * @param string $_
168
     * @return \PhpBoot\DB\rules\select\OrderByRule
169
     */
170 2
    public function having($expr, $_=null) {
0 ignored issues
show
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171 2
        WhereImpl::having($this->context, $expr, array_slice(func_get_args(), 1));
172 2
        return new OrderByRule($this->context);
173
    }
174
//    /**
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
175
//     *
176
//     *
177
//     *
178
//     * @param array $args
179
//     * @return \PhpBoot\DB\rules\select\OrderByRule
180
//     */
181
//    public function havingArgs($args) {
182
//        WhereImpl::havingArgs($this->context, $args);
183
//        return new OrderByRule($this->context);
184
//    }
185
}
186
class GroupByRule extends OrderByRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
187
{
188
    /**
189
     * groupBy('column') => "GROUP BY column"
190
     * @param string $column
191
     * @return \PhpBoot\DB\rules\select\HavingRule
192
     */
193 3
    public function groupBy($column) {
194 3
        GroupByImpl::groupBy($this->context, $column);
195 3
        return new HavingRule($this->context);
196
    }
197
}
198
class WhereRule extends GroupByRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
199
{
200
    /**
201
     * where('a=?', 1) => "WHERE a=1"
202
     * where('a=?', Sql::raw('now()')) => "WHERE a=now()"
203
     * where('a IN (?)',  [1, 2]) => "WHERE a IN (1,2)"
204
     * where([
205
     *      'a'=>1,
206
     *      'b'=>['IN'=>[1,2]]
207
     *      'c'=>['BETWEEN'=>[1,2]]
208
     *      'd'=>['<>'=>1]
209
     *      ])
210
     *      =>
211
     *      "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
212
     * @param string|array $conditions
213
     * //TODO where(callable $query)
214
     * @param mixed $_
215
     * @return \PhpBoot\DB\rules\select\GroupByRule
216
     */
217 6
    public function where($conditions=null, $_=null) {
0 ignored issues
show
Unused Code introduced by
The parameter $_ is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
218 6
        WhereImpl::where($this->context, $conditions, array_slice(func_get_args(), 1));
219 6
        return new GroupByRule($this->context);
220
    }
221
}
222
223
class JoinRule extends WhereRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
224
{
225
    /**
226
     * join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
227
     * @param string $table
228
     * @return \PhpBoot\DB\rules\select\JoinOnRule
229
     */
230 2
    public function join($table){
231 2
        JoinImpl::join($this->context,null, $table);
232 2
        return new JoinOnRule($this->context);
233
    }
234
    /**
235
     * leftJoin('table1')->on('table0.id=table1.id') => "LEFT JOIN table1 ON table0.id=table1.id"
236
     * @param string $table
237
     * @return \PhpBoot\DB\rules\select\JoinOnRule
238
     */
239 1
    public function leftJoin($table){
240 1
        JoinImpl::join($this->context,'LEFT', $table);
241 1
        return new JoinOnRule($this->context);
242
    }
243
    /**
244
     * rightJoin('table1')->on('table0.id=table1.id') => "RIGHT JOIN table1 ON table0.id=table1.id"
245
     * @param string $table
246
     * @return \PhpBoot\DB\rules\select\JoinOnRule
247
     */
248 1
    public function rightJoin($table) {
249 1
        JoinImpl::join($this->context,'RIGHT', $table);
250 1
        return new JoinOnRule($this->context);
251
    }
252
    /**
253
     * innerJoin('table1')->on('table0.id=table1.id') => "INNER JOIN table1 ON table0.id=table1.id"
254
     * @param string $table
255
     * @return \PhpBoot\DB\rules\select\JoinOnRule
256
     */
257 1
    public function innerJoin($table) {
258 1
        JoinImpl::join($this->context,'INNER', $table);
259 1
        return new JoinOnRule($this->context);
260
    }
261
}
262
263
class JoinOnRule extends BasicRule
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
264
{
265
    /**
266
     * join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
267
     * @param string $condition
268
     * @return \PhpBoot\DB\rules\select\JoinRule
269
     */
270 5
    public function on($condition){
271 5
        JoinOnImpl::on($this->context, $condition);
272 5
        return new JoinRule($this->context);
273
    }
274
}
275