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

SubQuery::where()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3.6511

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 2
dl 15
loc 15
ccs 7
cts 12
cp 0.5833
crap 3.6511
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 12 and the first side effect is on line 10.

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\basic;
3
4
use PhpBoot\DB\Context;
5
use PhpBoot\DB\impls\ExecImpl;
6
use PhpBoot\DB\impls\LimitImpl;
7
use PhpBoot\DB\impls\OrderByImpl;
8
use PhpBoot\DB\impls\ExecResult;
9
use PhpBoot\DB\impls\WhereImpl;
10 1
require_once dirname(__DIR__).'/impls.php';
11
12
class BasicRule
13
{
14 49
    public function __construct(Context $context){
15 49
        $this->context = $context;
16 49
    }
17
18
19
    /**
20
     * @var Context
21
     */
22
    public $context;
23
}
24
25
class ExecRule 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...
26
{
27
    /**
28
     * Execute sql
29
     * @return ExecResult
30
     */
31 25
    public function exec() {
32 25
        return ExecImpl::exec($this->context);
33
    }
34
}
35
36
class LimitRule extends ExecRule
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...
37
{
38
    /**
39
     * limit(1) => "LIMIT 1"
40
     * @param int $size
41
     * @return \PhpBoot\DB\rules\basic\ExecRule
42
     */
43 3
    public function limit($size) {
44 3
        LimitImpl::limit($this->context, $size);
45 3
        return new ExecRule($this->context);
46
    }
47
}
48
49
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...
50
{
51 18
    public function __construct($context){
52 18
        parent::__construct($context);
53 18
        $this->impl = new OrderByImpl();
54 18
    }
55
    /**
56
     * 
57
     * orderBy('column') => "ORDER BY column"
58
     * orderBy('column', Sql::ORDER_BY_ASC) => "ORDER BY column ASC"
59
     * orderBy('column0')->orderBy('column1') => "ORDER BY column0, column1"
60
     * orderBy(['column0', 'column1'=>Sql::ORDER_BY_ASC]) => "ORDER BY column0,column1 ASC"
61
     * @param string $column
62
     * @param string $order Sql::ORDER_BY_ASC or Sql::ORDER_BY_DESC
63
     * 
64
     * @return \PhpBoot\DB\rules\basic\LimitRule
65
     */
66 4
    public function orderBy($column, $order=null) {
67 4
        $this->impl->orderBy($this->context, $column, $order);
68 4
        return new LimitRule($this->context);
69
    }
70
    private $impl;
71
}
72
73 View Code Duplication
class WhereRule 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...
74
{
75 18
    public function __construct(Context $context, $isTheFirst = true)
76
    {
77 18
        parent::__construct($context);
78 18
        $this->isTheFirst = $isTheFirst;
79 18
    }
80
81
    /**
82
     * where('a=?', 1) => "WHERE a=1"
83
     * where('a=?', Sql::raw('now()')) => "WHERE a=now()"
84
     * where('a IN (?)',  [1, 2]) => "WHERE a IN (1,2)"
85
     * where([
86
     *      'a'=>1,
87
     *      'b'=>['IN'=>[1,2]]
88
     *      'c'=>['BETWEEN'=>[1,2]]
89
     *      'd'=>['<>'=>1]
90
     *      ])
91
     *      =>
92
     *      "WHERE a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1"
93
     *
94
     * @param string|array|callable $conditions
95
     * @param mixed $_
96
     * @return WhereRule
97
     */
98 16
    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...
99 16
        if(is_callable($conditions)){
100
            $callback = function ($context)use($conditions){
101 1
                $rule = new SubQuery($context);
102 1
                $conditions($rule);
103 1
            };
104 1
            $conditions = $callback;
105 1
        }
106 16
        if($this->isTheFirst){
107 16
            WhereImpl::where($this->context, 'WHERE' ,$conditions, array_slice(func_get_args(), 1));
108 16
        }else{
109 2
            WhereImpl::where($this->context, 'AND', $conditions, array_slice(func_get_args(), 1));
110
        }
111 16
        return new WhereRule($this->context, false);
112
    }
113
114
    /**
115
     * orWhere('a=?', 1) => "OR a=1"
116
     * orWhere('a=?', Sql::raw('now()')) => "OR a=now()"
117
     * orWhere('a IN (?)',  [1, 2]) => "OR a IN (1,2)"
118
     * orWhere([
119
     *      'a'=>1,
120
     *      'b'=>['IN'=>[1,2]]
121
     *      'c'=>['BETWEEN'=>[1,2]]
122
     *      'd'=>['<>'=>1]
123
     *      ])
124
     *      =>
125
     *      "OR (a=1 AND b IN(1,2) AND c BETWEEN 1 AND 2 AND d<>1)"
126
     *
127
     * @param string|array|callable $conditions
128
     * @param mixed $_
129
     * @return WhereRule
130
     */
131 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...
132 1
        if(is_callable($conditions)){
133
            $callback = function ($context)use($conditions){
134
                $rule = new SubQuery($context);
135
                $conditions($rule);
136
            };
137
            $conditions = $callback;
138
        }
139 1
        WhereImpl::where($this->context, 'OR', $conditions, array_slice(func_get_args(), 1));
140 1
        return new WhereRule($this->context, false);
141
    }
142
    private $isTheFirst;
143
}
144
145 View Code Duplication
class SubQuery extends BasicRule
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...
146
{
147
148 3
    public function __construct(Context $context, $isTheFirst = true)
149
    {
150 3
        parent::__construct($context);
151 3
        $this->isTheFirst = $isTheFirst;
152 3
    }
153
154
    /**
155
     * @param $expr
156
     * @param null $_
157
     * @return SubQuery
158
     */
159 3
    public function where($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...
160 3
        if(is_callable($expr)){
161
            $callback = function ($context)use($expr){
162
                $rule = new SubQuery($context, true);
163
                $expr($rule);
164
            };
165
            $expr = $callback;
166
        }
167 3
        if($this->isTheFirst){
168 3
            WhereImpl::where($this->context, '', $expr, array_slice(func_get_args(), 1));
169 3
        }else{
170 3
            WhereImpl::where($this->context, 'AND', $expr, array_slice(func_get_args(), 1));
171
        }
172 3
        return new SubQuery($this->context, false);
173
    }
174
    /**
175
     * @param $expr
176
     * @param null $_
177
     * @return SubQuery
178
     */
179 3
    public function orWhere($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...
180 3
        if(is_callable($expr)){
181
            $callback = function ($context)use($expr){
182
                $rule = new SubQuery($context, true);
183
                $expr($rule);
184
            };
185
            $expr = $callback;
186
        }
187 3
        WhereImpl::where($this->context, 'OR', $expr, array_slice(func_get_args(), 1));
188 3
        return new SubQuery($this->context, false);
189
    }
190
191
    private $isTheFirst;
192
}