| Conditions | 10 |
| Paths | 14 |
| Total Lines | 49 |
| Code Lines | 35 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 = [ |
||
| 51 | $field, |
||
| 52 | $operator, |
||
| 53 | $this->queryStructure->bindParam( 'min', $min ), |
||
| 54 | 'AND', |
||
| 55 | $this->queryStructure->bindParam( 'max', $max ) |
||
| 56 | ]; |
||
| 57 | $body = implode( ' ', $body ); |
||
| 58 | $this->queryStructure->setElement( $clauseType, array( 'glue' => $glue, 'body' => $body, 'type' => 'cond' ) ); |
||
| 59 | break; |
||
| 60 | |||
| 61 | case 'IN': |
||
| 62 | case 'NOT IN': |
||
| 63 | case '!IN': |
||
| 64 | if ( is_a( $value, QuerySelect::class ) ) |
||
| 65 | return $this->inSelectObject( $field, $value, $operator, $glue, $clauseType ); |
||
| 66 | elseif ( is_array( $value ) ) |
||
| 67 | return $this->inArray( $field, $value, $operator, $glue, $clauseType ); |
||
| 68 | break; |
||
| 69 | |||
| 70 | default: |
||
| 71 | $valuePdoString = $this->queryStructure->bindParam( $field, $value ); |
||
| 72 | $body = $field . ' ' . $operator . ' ' . $valuePdoString; |
||
| 73 | $this->queryStructure->setElement( $clauseType, array( 'glue' => $glue, 'body' => $body, 'type' => 'cond' ) ); |
||
| 74 | |||
| 75 | } |
||
| 76 | |||
| 77 | return $this; |
||
| 78 | |||
| 200 | } |