Skip to content

Commit e1972dc

Browse files
feat: replace DB::raw() with first argument string
1 parent 51274ad commit e1972dc

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ DB::select(DB::raw('select 1'));
8888
### After
8989

9090
```php
91-
DB::select(DB::raw('select 1')->getValue(DB::getQueryGrammar()));
91+
DB::select('select 1');
9292
```
9393

9494
## License

src/LaravelDatabaseExpressionsRector.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function getRuleDefinition(): RuleDefinition
2323
[
2424
new CodeSample(
2525
"DB::select(DB::raw('select 1'));",
26-
"DB::select(DB::raw('select 1')->getValue(DB::getQueryGrammar()));"
26+
"DB::select('select 1');"
2727
),
2828
]
2929
);
@@ -60,18 +60,7 @@ public function refactor(Node $node): ?Node
6060
return null;
6161
}
6262

63-
$arguments[] = new Arg(
64-
new StaticCall(
65-
new Name('DB'),
66-
'getQueryGrammar'
67-
)
68-
);
69-
70-
$node->args[0]->value = new MethodCall(
71-
$childNode,
72-
new Identifier('getValue'),
73-
$arguments
74-
);
63+
$node->args[0]->value = $childNode->args[0]->value;
7564

7665
return $node;
7766
}

tests/fixture/TestFixture.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ declare(strict_types=1);
2424

2525
use Illuminate\Support\Facades\DB;
2626

27-
DB::select(DB::raw('select 1')->getValue(DB::getQueryGrammar()));
27+
DB::select('select 1');
2828

2929
DB::select(
30-
DB::raw('select 2')->getValue(DB::getQueryGrammar())
30+
'select 2'
3131
);
3232

3333
$orders = DB::table('orders')
34-
->selectRaw(DB::raw('price * ? as price_with_tax')->getValue(DB::getQueryGrammar()), [1.0825])
34+
->selectRaw('price * ? as price_with_tax', [1.0825])
3535
->get();
3636

3737
$orders = DB::table('orders')
38-
->whereRaw(DB::raw('price > IF(state = "TX", ?, 100)')->getValue(DB::getQueryGrammar()), [200])
38+
->whereRaw('price > IF(state = "TX", ?, 100)', [200])
3939
->get();

0 commit comments

Comments
 (0)