| @@ -13,82 +13,82 @@ | ||
| 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' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], | |
| 51 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], | |
| 50 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], | |
| 51 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], | |
| 52 | 52 | ]], | 
| 53 | 53 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'joe%', ':p1'=> 'bruce%']] | 
| 54 | 54 | ], | 
| 55 | 55 | [ | 
| 56 | 56 | ['condition' => "and", 'rules' => [ | 
| 57 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], | |
| 58 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], | |
| 57 | + ['field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], | |
| 58 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], | |
| 59 | 59 | ]], | 
| 60 | 60 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%thomas%', ':p1'=> '%paul%']] | 
| 61 | 61 | ], | 
| 62 | 62 | [ | 
| 63 | 63 | ['condition' => "and", 'rules' => [ | 
| 64 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], | |
| 65 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], | |
| 64 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], | |
| 65 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], | |
| 66 | 66 | ]], | 
| 67 | 67 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%brian', ':p1'=> '%david']] | 
| 68 | 68 | ], | 
| 69 | 69 | [ | 
| 70 | 70 | ['condition' => "or", 'rules' => [ | 
| 71 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], | |
| 72 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], | |
| 73 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_null'], | |
| 74 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], | |
| 71 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], | |
| 72 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], | |
| 73 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_null'], | |
| 74 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], | |
| 75 | 75 | ]], | 
| 76 | 76 | ['(name = "" or name <> "" or name IS NULL or name IS NOT NULL)', []] | 
| 77 | 77 | ], | 
| 78 | 78 | [ | 
| 79 | 79 | ['condition' => "and", 'rules' => [ | 
| 80 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], | |
| 81 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], | |
| 80 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], | |
| 81 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], | |
| 82 | 82 | ['condition' => 'or', 'rules'=>[ | 
| 83 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 84 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], | |
| 83 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], | |
| 84 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], | |
| 85 | 85 | ['condition' => 'and', 'rules'=>[ | 
| 86 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], | |
| 86 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], | |
| 87 | 87 | ]] | 
| 88 | 88 | ]] | 
| 89 | 89 | ]], | 
| 90 | 90 | ['(name LIKE :p0 and name LIKE :p1 and (name = :p2 or name = :p3 or (id = :p4)))', [ | 
| 91 | - ':p0'=>'kurt%',':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 | |
| 91 | + ':p0'=>'kurt%', ':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 | |
| 92 | 92 | ]] | 
| 93 | 93 | ] | 
| 94 | 94 | |
| @@ -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'); | |
| @@ -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 | |
| @@ -58,19 +58,19 @@ 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 | -            'begins_with' =>      ['op' => 'LIKE ?',     'fn' => function($value){ return "$value%"; } ], | |
| 69 | -            'not_begins_with' =>  ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "$value%"; } ], | |
| 70 | -            'contains' =>         ['op' => 'LIKE ?',     'fn' => function($value){ return "%$value%"; } ], | |
| 71 | -            'not_contains' =>     ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value%"; } ], | |
| 72 | -            'ends_with' =>        ['op' => 'LIKE ?',     'fn' => function($value){ return "%$value"; } ], | |
| 73 | -            'not_ends_with' =>    ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value"; } ], | |
| 67 | + 'between' => ['op' => 'BETWEEN ?', 'list' => true, 'sep' => ' AND '], | |
| 68 | +            'begins_with' =>      ['op' => 'LIKE ?', 'fn' => function($value) { return "$value%"; }], | |
| 69 | +            'not_begins_with' =>  ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "$value%"; }], | |
| 70 | +            'contains' =>         ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value%"; }], | |
| 71 | +            'not_contains' =>     ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value%"; }], | |
| 72 | +            'ends_with' =>        ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value"; }], | |
| 73 | +            'not_ends_with' =>    ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value"; }], | |
| 74 | 74 | 'is_empty' => '= ""', | 
| 75 | 75 | 'is_not_empty' => '<> ""', | 
| 76 | 76 | 'is_null' => 'IS NULL', | 
| @@ -96,7 +96,7 @@ discard block | ||
| 96 | 96 |          } else { | 
| 97 | 97 | $op = ArrayHelper::getValue($pattern, 'op'); | 
| 98 | 98 | $list = ArrayHelper::getValue($pattern, 'list'); | 
| 99 | -            if ($list){ | |
| 99 | +            if ($list) { | |
| 100 | 100 | $sep = ArrayHelper::getValue($pattern, 'sep'); | 
| 101 | 101 | $replacement = implode($sep, $keys); | 
| 102 | 102 |              } else { | 
| @@ -108,7 +108,7 @@ discard block | ||
| 108 | 108 | } | 
| 109 | 109 | |
| 110 | 110 | $this->_params = array_merge($this->_params, $params); | 
| 111 | -        return $field . " " . ($replacement ? str_replace("?", $replacement, $pattern) : $pattern); | |
| 111 | +        return $field." ".($replacement ? str_replace("?", $replacement, $pattern) : $pattern); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | /** | 
| @@ -122,7 +122,7 @@ discard block | ||
| 122 | 122 | } | 
| 123 | 123 | |
| 124 | 124 | $where = []; | 
| 125 | - $condition = " " . $data['condition'] . " "; | |
| 125 | + $condition = " ".$data['condition']." "; | |
| 126 | 126 | |
| 127 | 127 |          foreach ($data['rules'] as $rule) { | 
| 128 | 128 |              if (isset($rule['condition'])) { | 
| @@ -148,7 +148,7 @@ discard block | ||
| 148 | 148 | $where[] = $this->encodeRule($field, $operator, $params); | 
| 149 | 149 | } | 
| 150 | 150 | } | 
| 151 | -        return "(" . implode($condition, $where) . ")"; | |
| 151 | +        return "(".implode($condition, $where).")"; | |
| 152 | 152 | } | 
| 153 | 153 | |
| 154 | 154 | /** |