| @@ -13,88 +13,88 @@ | ||
| 13 | 13 | return [ | 
| 14 | 14 | [ | 
| 15 | 15 | ['condition' => "and", 'rules' => [ | 
| 16 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 17 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_equal', 'value' => 'bruce'] | |
| 16 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 17 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_equal', 'value' => 'bruce'] | |
| 18 | 18 | ]], | 
| 19 | 19 | ['(name = :p0 and name <> :p1)', [':p0' => 'joe', ':p1' => 'bruce']] | 
| 20 | 20 | ], | 
| 21 | 21 | [ | 
| 22 | 22 | ['condition' => "and", 'rules' => [ | 
| 23 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'in', 'value' => [1,2,3]], | |
| 24 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'not_in', 'value' => [4,5]] | |
| 23 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'in', 'value' => [1, 2, 3]], | |
| 24 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'not_in', 'value' => [4, 5]] | |
| 25 | 25 | ]], | 
| 26 | 26 | ['(id IN (:p0, :p1, :p2) and id NOT IN (:p3, :p4))', [':p0'=>1, ':p1'=>2, ':p2'=>3, ':p3'=>4, ':p4'=>5]] | 
| 27 | 27 | ], | 
| 28 | 28 | [ | 
| 29 | 29 | ['condition' => "and", 'rules' => [ | 
| 30 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'less', 'value' => 100], | |
| 31 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'less_or_equal', 'value' => 50], | |
| 30 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'less', 'value' => 100], | |
| 31 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'less_or_equal', 'value' => 50], | |
| 32 | 32 | ]], | 
| 33 | 33 | ['(id < :p0 and id <= :p1)', [':p0'=>100, ':p1'=>50]] | 
| 34 | 34 | ], | 
| 35 | 35 | [ | 
| 36 | 36 | ['condition' => "and", 'rules' => [ | 
| 37 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'greater', 'value' => 10], | |
| 38 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'greater_or_equal', 'value' => 20], | |
| 37 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'greater', 'value' => 10], | |
| 38 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'greater_or_equal', 'value' => 20], | |
| 39 | 39 | ]], | 
| 40 | 40 | ['(id > :p0 and id >= :p1)', [':p0'=>10, ':p1'=>20]] | 
| 41 | 41 | ], | 
| 42 | 42 | [ | 
| 43 | 43 | ['condition' => "and", 'rules' => [ | 
| 44 | - [ 'field' => 'date', 'type' => 'date', 'operator' => 'between', 'value' => ['2015-01-01','2015-01-30']], | |
| 44 | + ['field' => 'date', 'type' => 'date', 'operator' => 'between', 'value' => ['2015-01-01', '2015-01-30']], | |
| 45 | 45 | ]], | 
| 46 | 46 | ['(date BETWEEN :p0 AND :p1)', [':p0'=>'2015-01-01', ':p1'=>'2015-01-30']] | 
| 47 | 47 | ], | 
| 48 | 48 | [ | 
| 49 | 49 | ['condition' => "and", 'rules' => [ | 
| 50 | - [ 'field' => 'date', 'type' => 'date', 'operator' => 'not_between', 'value' => ['2015-01-01','2015-01-30']], | |
| 50 | + ['field' => 'date', 'type' => 'date', 'operator' => 'not_between', 'value' => ['2015-01-01', '2015-01-30']], | |
| 51 | 51 | ]], | 
| 52 | 52 | ['(date NOT BETWEEN :p0 AND :p1)', [':p0'=>'2015-01-01', ':p1'=>'2015-01-30']] | 
| 53 | 53 | ], | 
| 54 | 54 | [ | 
| 55 | 55 | ['condition' => "and", 'rules' => [ | 
| 56 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], | |
| 57 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], | |
| 56 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], | |
| 57 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], | |
| 58 | 58 | ]], | 
| 59 | 59 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'joe%', ':p1'=> 'bruce%']] | 
| 60 | 60 | ], | 
| 61 | 61 | [ | 
| 62 | 62 | ['condition' => "and", 'rules' => [ | 
| 63 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], | |
| 64 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], | |
| 63 | + ['field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], | |
| 64 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], | |
| 65 | 65 | ]], | 
| 66 | 66 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%thomas%', ':p1'=> '%paul%']] | 
| 67 | 67 | ], | 
| 68 | 68 | [ | 
| 69 | 69 | ['condition' => "and", 'rules' => [ | 
| 70 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], | |
| 71 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], | |
| 70 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], | |
| 71 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], | |
| 72 | 72 | ]], | 
| 73 | 73 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%brian', ':p1'=> '%david']] | 
| 74 | 74 | ], | 
| 75 | 75 | [ | 
| 76 | 76 | ['condition' => "or", 'rules' => [ | 
| 77 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], | |
| 78 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], | |
| 79 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_null'], | |
| 80 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], | |
| 77 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], | |
| 78 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], | |
| 79 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_null'], | |
| 80 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], | |
| 81 | 81 | ]], | 
| 82 | 82 | ['(name = "" or name <> "" or name IS NULL or name IS NOT NULL)', []] | 
| 83 | 83 | ], | 
| 84 | 84 | [ | 
| 85 | 85 | ['condition' => "and", 'rules' => [ | 
| 86 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], | |
| 87 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], | |
| 86 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], | |
| 87 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], | |
| 88 | 88 | ['condition' => 'or', 'rules'=>[ | 
| 89 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 90 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], | |
| 89 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 90 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], | |
| 91 | 91 | ['condition' => 'and', 'rules'=>[ | 
| 92 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], | |
| 92 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], | |
| 93 | 93 | ]] | 
| 94 | 94 | ]] | 
| 95 | 95 | ]], | 
| 96 | 96 | ['(name LIKE :p0 and name LIKE :p1 and (name = :p2 or name = :p3 or (id = :p4)))', [ | 
| 97 | - ':p0'=>'kurt%',':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 | |
| 97 | + ':p0'=>'kurt%', ':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 | |
| 98 | 98 | ]] | 
| 99 | 99 | ] | 
| 100 | 100 | |
| @@ -17,14 +17,14 @@ discard block | ||
| 17 | 17 | */ | 
| 18 | 18 | public static function setUpBeforeClass() | 
| 19 | 19 |      { | 
| 20 | - $vendorDir = __DIR__ . '/../vendor'; | |
| 21 | - $vendorAutoload = $vendorDir . '/autoload.php'; | |
| 20 | + $vendorDir = __DIR__.'/../vendor'; | |
| 21 | + $vendorAutoload = $vendorDir.'/autoload.php'; | |
| 22 | 22 |          if (file_exists($vendorAutoload)) { | 
| 23 | 23 | require_once($vendorAutoload); | 
| 24 | 24 |          } else { | 
| 25 | 25 |              throw new NotSupportedException("Vendor autoload file '{$vendorAutoload}' is missing."); | 
| 26 | 26 | } | 
| 27 | - require_once($vendorDir . '/yiisoft/yii2/Yii.php'); | |
| 27 | + require_once($vendorDir.'/yiisoft/yii2/Yii.php'); | |
| 28 | 28 |          Yii::setAlias('@vendor', $vendorDir); | 
| 29 | 29 | } | 
| 30 | 30 | |
| @@ -37,7 +37,7 @@ discard block | ||
| 37 | 37 | 'id' => 'querybuilder-test', | 
| 38 | 38 | 'basePath' => __DIR__, | 
| 39 | 39 | ]; | 
| 40 | - $config['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor'; | |
| 40 | + $config['vendorPath'] = dirname(dirname(__DIR__)).'/vendor'; | |
| 41 | 41 | new \yii\console\Application($config); | 
| 42 | 42 | } | 
| 43 | 43 | |
| @@ -5,12 +5,12 @@ | ||
| 5 | 5 | |
| 6 | 6 |  define('YII_ENABLE_ERROR_HANDLER', false); | 
| 7 | 7 |  define('YII_DEBUG', true); | 
| 8 | -$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; | |
| 8 | +$_SERVER['SCRIPT_NAME'] = '/'.__DIR__; | |
| 9 | 9 | $_SERVER['SCRIPT_FILENAME'] = __FILE__; | 
| 10 | 10 | |
| 11 | 11 | // require composer autoloader if available | 
| 12 | -$vendor = __DIR__ . '/../vendor'; | |
| 12 | +$vendor = __DIR__.'/../vendor'; | |
| 13 | 13 | |
| 14 | -require_once($vendor . '/autoload.php'); | |
| 15 | -require_once($vendor . '/yiisoft/yii2/Yii.php'); | |
| 16 | -require_once(__DIR__ . '/TestCase.php'); | |
| 14 | +require_once($vendor.'/autoload.php'); | |
| 15 | +require_once($vendor.'/yiisoft/yii2/Yii.php'); | |
| 16 | +require_once(__DIR__.'/TestCase.php'); | |
| @@ -58,20 +58,20 @@ discard block | ||
| 58 | 58 | $this->_operators = [ | 
| 59 | 59 | 'equal' => '= ?', | 
| 60 | 60 | 'not_equal' => '<> ?', | 
| 61 | - 'in' => ['op' => 'IN (?)', 'list' => true, 'sep' => ', ' ], | |
| 61 | + 'in' => ['op' => 'IN (?)', 'list' => true, 'sep' => ', '], | |
| 62 | 62 | 'not_in' => ['op' => 'NOT IN (?)', 'list' => true, 'sep' => ', '], | 
| 63 | 63 | 'less' => '< ?', | 
| 64 | 64 | 'less_or_equal' => '<= ?', | 
| 65 | 65 | 'greater' => '> ?', | 
| 66 | 66 | 'greater_or_equal' => '>= ?', | 
| 67 | - 'between' => ['op' => 'BETWEEN ?', 'list' => true, 'sep' => ' AND '], | |
| 68 | - 'not_between' => ['op' => 'NOT BETWEEN ?', 'list' => true, 'sep' => ' AND '], | |
| 69 | -            'begins_with' =>      ['op' => 'LIKE ?',     'fn' => function($value){ return "$value%"; } ], | |
| 70 | -            'not_begins_with' =>  ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "$value%"; } ], | |
| 71 | -            'contains' =>         ['op' => 'LIKE ?',     'fn' => function($value){ return "%$value%"; } ], | |
| 72 | -            'not_contains' =>     ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value%"; } ], | |
| 73 | -            'ends_with' =>        ['op' => 'LIKE ?',     'fn' => function($value){ return "%$value"; } ], | |
| 74 | -            'not_ends_with' =>    ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value"; } ], | |
| 67 | + 'between' => ['op' => 'BETWEEN ?', 'list' => true, 'sep' => ' AND '], | |
| 68 | + 'not_between' => ['op' => 'NOT BETWEEN ?', 'list' => true, 'sep' => ' AND '], | |
| 69 | +            'begins_with' =>      ['op' => 'LIKE ?', 'fn' => function($value) { return "$value%"; }], | |
| 70 | +            'not_begins_with' =>  ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "$value%"; }], | |
| 71 | +            'contains' =>         ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value%"; }], | |
| 72 | +            'not_contains' =>     ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value%"; }], | |
| 73 | +            'ends_with' =>        ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value"; }], | |
| 74 | +            'not_ends_with' =>    ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value"; }], | |
| 75 | 75 | 'is_empty' => '= ""', | 
| 76 | 76 | 'is_not_empty' => '<> ""', | 
| 77 | 77 | 'is_null' => 'IS NULL', | 
| @@ -97,7 +97,7 @@ discard block | ||
| 97 | 97 |          } else { | 
| 98 | 98 | $op = ArrayHelper::getValue($pattern, 'op'); | 
| 99 | 99 | $list = ArrayHelper::getValue($pattern, 'list'); | 
| 100 | -            if ($list){ | |
| 100 | +            if ($list) { | |
| 101 | 101 | $sep = ArrayHelper::getValue($pattern, 'sep'); | 
| 102 | 102 | $replacement = implode($sep, $keys); | 
| 103 | 103 |              } else { | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 | } | 
| 110 | 110 | |
| 111 | 111 | $this->_params = array_merge($this->_params, $params); | 
| 112 | -        return $field . " " . ($replacement ? str_replace("?", $replacement, $pattern) : $pattern); | |
| 112 | +        return $field." ".($replacement ? str_replace("?", $replacement, $pattern) : $pattern); | |
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | 115 | /** | 
| @@ -123,7 +123,7 @@ discard block | ||
| 123 | 123 | } | 
| 124 | 124 | |
| 125 | 125 | $where = []; | 
| 126 | - $condition = " " . $data['condition'] . " "; | |
| 126 | + $condition = " ".$data['condition']." "; | |
| 127 | 127 | |
| 128 | 128 |          foreach ($data['rules'] as $rule) { | 
| 129 | 129 |              if (isset($rule['condition'])) { | 
| @@ -149,7 +149,7 @@ discard block | ||
| 149 | 149 | $where[] = $this->encodeRule($field, $operator, $params); | 
| 150 | 150 | } | 
| 151 | 151 | } | 
| 152 | -        return "(" . implode($condition, $where) . ")"; | |
| 152 | +        return "(".implode($condition, $where).")"; | |
| 153 | 153 | } | 
| 154 | 154 | |
| 155 | 155 | /** |