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.
Completed
Push — master ( 37c075...91da2e )
by cao
03:14
created

WhereRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 5
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 21 and the first side effect is on line 18.

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\Context;
4
use PhpBoot\DB\rules\basic\BasicRule;
5
use PhpBoot\DB\impls\ExecImpl;
6
use PhpBoot\DB\impls\SelectImpl;
7
use PhpBoot\DB\impls\FromImpl;
8
use PhpBoot\DB\impls\JoinImpl;
9
use PhpBoot\DB\impls\JoinOnImpl;
10
use PhpBoot\DB\impls\WhereImpl;
11
use PhpBoot\DB\impls\GroupByImpl;
12
use PhpBoot\DB\impls\OrderByImpl;
13
use PhpBoot\DB\impls\LimitImpl;
14
use PhpBoot\DB\impls\ForUpdateOfImpl;
15
use PhpBoot\DB\impls\ForUpdateImpl;
16
use PhpBoot\DB\rules\basic\SubQuery;
17
18 1
require_once dirname(__DIR__).'/impls.php';
19 1
require_once __DIR__.'/basic.php';
20
21
class SelectRule extends BasicRule
22
{
23
    /**
24
     * select('column0, column1') => "SELECT column0, column1"
25
     * select('column0', 'column1') => "SELECT column0, column1"
26
     * @param string $columns
27
     * @return \PhpBoot\DB\rules\select\FromRule
28
     */
29 24
    public function select($columns) {
30 24
        SelectImpl::select($this->context, $columns);
31 24
        return new FromRule($this->context);
32
    }
33
}
34
35
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...
36
{
37
    /**
38
     * Execute sql and get responses
39
     * @param string|false $asDict
40
     * @return array
41
     */
42 23
    public function get($asDict=false) {
43 23
        return ExecImpl::get($this->context, $asDict);
0 ignored issues
show
Bug introduced by
It seems like $asDict defined by parameter $asDict on line 42 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...
44
    }
45
46
    /**
47
     * @return int|false
48
     */
49
    public function count() {
50
        return ExecImpl::count($this->context);
51
    }
52
    /**
53
     * Execute sql and get one response
54
     * @return null
55
     */
56 1
    public function getFirst(){
57 1
        $res = ExecImpl::get($this->context);
58 1
        if(count($res)){
59 1
            return $res[0];
60
        }
61
        return null;
62
    }
63
}
64
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...
65
{
66
    /**
67
     * from('table') => "FROM table"
68
     * @param string $table
69
     * @return \PhpBoot\DB\rules\select\JoinRule
70
     */
71 23
    public function from($table, $as=null){
72 23
        FromImpl::from($this->context, $table,$as);
73 23
        return new JoinRule($this->context);
74
    }
75
}
76
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...
77
{
78
    /**
79
     * forUpdate()->of('column') => 'FOR UPDATE OF column'
80
     * @param string $column
81
     * @return \PhpBoot\DB\rules\select\GetRule
82
     */
83 1
    public function of($column){
84 1
        ForUpdateOfImpl::of($this->context, $column);
85 1
        return new GetRule($this->context);
86
    }
87
}
88
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...
89
{
90
    /**
91
     * forUpdate() => 'FOR UPDATE'
92
     * @return \PhpBoot\DB\rules\select\ForUpdateOfRule
93
     */
94 2
    public function forUpdate(){
95 2
        ForUpdateImpl::forUpdate($this->context);
96 2
        return new ForUpdateOfRule($this->context);
97
    }
98
}
99
100
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...
101
{
102
    /**
103
     * limit(0,1) => "LIMIT 0,1"
104
     * @param int $start
105
     * @param int $size
106
     * @return \PhpBoot\DB\rules\select\ForUpdateRule
107
     */
108 1
    public function limit($start, $size) {
109 1
        LimitImpl::limitWithOffset($this->context, $start, $size);
110 1
        return new ForUpdateRule($this->context);
111
    }
112
}
113
114
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...
115
{
116 23
    public function __construct($context){
117 23
        parent::__construct($context);
118 23
        $this->order = new OrderByImpl();
119 23
    }
120
    /**
121
     * orderBy('column') => "ORDER BY column"
122
     * orderBy('column', Sql::ORDER_BY_ASC) => "ORDER BY column ASC"
123
     * orderBy('column0')->orderBy('column1') => "ORDER BY column0, column1"
124
     *
125
     * orderBy(['column0', 'column1'=>Sql::ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
126
     *
127
     * @param string $column
128
     * @param string $order Sql::ORDER_BY_ASC or Sql::ORDER_BY_DESC
129
     * @return \PhpBoot\DB\rules\select\OrderByRule
130
     */
131 3
    public function orderBy($column, $order=null) {
132 3
        $this->order->orderBy($this->context, $column, $order);
133 3
        return $this;
134
    }
135
//    /**
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...
136
//     * orderByArgs(['column0', 'column1'=>Sql::ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
137
//     * @param array $args
138
//     * @return \PhpBoot\DB\rules\select\OrderByRule
139
//     */
140
//    public function orderByArgs($args) {
141
//        $this->order->orderByArgs($this->context, $args);
142
//        return $this;
143
//    }
144
    /**
145
     * @var OrderByImpl
146
     */
147
    private $order;
148
}
149
150 View Code Duplication
class HavingRule extends OrderByRule
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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...
151
{
152 5
    public function __construct(Context $context, $isTheFirst = true)
153
    {
154 5
        parent::__construct($context);
155 5
        $this->isTheFirst = $isTheFirst;
156 5
    }
157
    /**
158
     *
159
     * having('SUM(a)=?', 1) => "HAVING SUM(a)=1"
160
     * having('a>?', Sql::raw('now()')) => "HAVING a>now()"
161
     * having('a IN (?)',  [1, 2]) => "HAVING a IN (1,2)"
162
     *
163
     * having([
164
     *      'a'=>1,
165
     *      'b'=>['IN'=>[1,2]]
166
     *      'c'=>['BETWEEN'=>[1,2]]
167
     *      'd'=>['<>'=>1]
168
     *      ])
169
     *
170
     *      =>
171
     *      "HAVING a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
172
     *
173
     * @param string|array|callable $expr
174
     * @param string $_
175
     * @return \PhpBoot\DB\rules\select\HavingRule
176
     */
177 4
    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...
178 4
        if(is_callable($expr)){
179
            $callback = function ($context)use($expr){
180 1
                $rule = new SubQuery($context);
181 1
                $expr($rule);
182 1
            };
183 1
            $expr = $callback;
184 1
        }
185 4
        if($this->isTheFirst){
186 4
            WhereImpl::where($this->context, 'HAVING', $expr, array_slice(func_get_args(), 1));
187 4
        }else{
188 2
            WhereImpl::where($this->context, 'AND', $expr, array_slice(func_get_args(), 1));
189
        }
190
191 4
        return new HavingRule($this->context, false);
192
    }
193
194
    /**
195
     *
196
     * orHaving('SUM(a)=?', 1) => "OR SUM(a)=1"
197
     * orHaving('a>?', Sql::raw('now()')) => "OR a>now()"
198
     * orHaving('a IN (?)',  [1, 2]) => "OR a IN (1,2)"
199
     *
200
     * orHaving([
201
     *      'a'=>1,
202
     *      'b'=>['IN'=>[1,2]]
203
     *      'c'=>['BETWEEN'=>[1,2]]
204
     *      'd'=>['<>'=>1]
205
     *      ])
206
     *
207
     *      =>
208
     *      "OR (a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1)"
209
     *
210
     * @param string|array|callable $expr
211
     * @param string $_
212
     * @return \PhpBoot\DB\rules\select\HavingRule
213
     */
214 1
    public function orHaving($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...
215 1
        if(is_callable($expr)){
216
            $callback = function ($context)use($expr){
217
                $rule = new SubQuery($context);
218
                $expr($rule);
219
            };
220
            $expr = $callback;
221
        }
222 1
        WhereImpl::where($this->context, 'OR', $expr, array_slice(func_get_args(), 1));
223 1
        return new HavingRule($this->context, false);
224
    }
225
226
    private $isTheFirst;
227
}
228
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...
229
{
230
    /**
231
     * groupBy('column') => "GROUP BY column"
232
     * @param string $column
233
     * @return \PhpBoot\DB\rules\select\HavingRule
234
     */
235 5
    public function groupBy($column) {
236 5
        GroupByImpl::groupBy($this->context, $column);
237 5
        return new HavingRule($this->context);
238
    }
239
}
240
241 View Code Duplication
class WhereRule extends GroupByRule
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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...
242
{
243 23
    public function __construct(Context $context, $isTheFirst = true)
244
    {
245 23
        parent::__construct($context);
246 23
        $this->isTheFirst = $isTheFirst;
247 23
    }
248
249
    /**
250
     * where('a=?', 1) => "WHERE a=1"
251
     * where('a=?', Sql::raw('now()')) => "WHERE a=now()"
252
     * where('a IN (?)',  [1, 2]) => "WHERE a IN (1,2)"
253
     * where([
254
     *      'a'=>1,
255
     *      'b'=>['IN'=>[1,2]]
256
     *      'c'=>['BETWEEN'=>[1,2]]
257
     *      'd'=>['<>'=>1]
258
     *      ])
259
     *      =>
260
     *      "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
261
     *
262
     * @param string|array|callable $conditions
263
     * @param mixed $_
264
     * @return \PhpBoot\DB\rules\select\WhereRule
265
     */
266 8
    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...
267 8
        if(is_callable($conditions)){
268
            $callback = function ($context)use($conditions){
269 1
                $rule = new SubQuery($context);
270 1
                $conditions($rule);
271 1
            };
272 1
            $conditions = $callback;
273 1
        }
274 8
        if($this->isTheFirst){
275 8
            WhereImpl::where($this->context, 'WHERE' ,$conditions, array_slice(func_get_args(), 1));
276 8
        }else{
277 2
            WhereImpl::where($this->context, 'AND', $conditions, array_slice(func_get_args(), 1));
278
        }
279 8
        return new WhereRule($this->context, false);
280
    }
281
282
    /**
283
     * orWhere('a=?', 1) => "OR a=1"
284
     * orWhere('a=?', Sql::raw('now()')) => "OR a=now()"
285
     * orWhere('a IN (?)',  [1, 2]) => "OR a IN (1,2)"
286
     * orWhere([
287
     *      'a'=>1,
288
     *      'b'=>['IN'=>[1,2]]
289
     *      'c'=>['BETWEEN'=>[1,2]]
290
     *      'd'=>['<>'=>1]
291
     *      ])
292
     *      =>
293
     *      "OR (a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1)"
294
     *
295
     * @param string|array|callable $conditions
296
     * @param mixed $_
297
     * @return \PhpBoot\DB\rules\select\WhereRule
298
     */
299 1
    public function orWhere($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...
300 1
        if(is_callable($conditions)){
301
            $callback = function ($context)use($conditions){
302
                $rule = new SubQuery($context);
303
                $conditions($rule);
304
            };
305
            $conditions = $callback;
306
        }
307 1
        WhereImpl::where($this->context, 'OR', $conditions, array_slice(func_get_args(), 1));
308 1
        return new WhereRule($this->context, false);
309
    }
310
    private $isTheFirst;
311
}
312
313
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...
314
{
315
    /**
316
     * join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
317
     * @param string $table
318
     * @return \PhpBoot\DB\rules\select\JoinOnRule
319
     */
320 2
    public function join($table){
321 2
        JoinImpl::join($this->context,null, $table);
322 2
        return new JoinOnRule($this->context);
323
    }
324
    /**
325
     * leftJoin('table1')->on('table0.id=table1.id') => "LEFT JOIN table1 ON table0.id=table1.id"
326
     * @param string $table
327
     * @return \PhpBoot\DB\rules\select\JoinOnRule
328
     */
329 1
    public function leftJoin($table){
330 1
        JoinImpl::join($this->context,'LEFT', $table);
331 1
        return new JoinOnRule($this->context);
332
    }
333
    /**
334
     * rightJoin('table1')->on('table0.id=table1.id') => "RIGHT JOIN table1 ON table0.id=table1.id"
335
     * @param string $table
336
     * @return \PhpBoot\DB\rules\select\JoinOnRule
337
     */
338 1
    public function rightJoin($table) {
339 1
        JoinImpl::join($this->context,'RIGHT', $table);
340 1
        return new JoinOnRule($this->context);
341
    }
342
    /**
343
     * innerJoin('table1')->on('table0.id=table1.id') => "INNER JOIN table1 ON table0.id=table1.id"
344
     * @param string $table
345
     * @return \PhpBoot\DB\rules\select\JoinOnRule
346
     */
347 1
    public function innerJoin($table) {
348 1
        JoinImpl::join($this->context,'INNER', $table);
349 1
        return new JoinOnRule($this->context);
350
    }
351
}
352
353
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...
354
{
355
    /**
356
     * join('table1')->on('table0.id=table1.id') => "JOIN table1 ON table0.id=table1.id"
357
     * @param string $condition
358
     * @return \PhpBoot\DB\rules\select\JoinRule
359
     */
360 5
    public function on($condition){
361 5
        JoinOnImpl::on($this->context, $condition);
362 5
        return new JoinRule($this->context);
363
    }
364
}
365