remarkablemark/rector-laravel-database-expressions
最新稳定版本:2.0.1
Composer 安装命令:
composer require remarkablemark/rector-laravel-database-expressions
包简介
Rector to fix Laravel 10 database expressions
README 文档
README
Rector to refactor Laravel 10 database expressions.
From Laravel 10:
Database "expressions" (typically generated via
DB::raw) have been rewritten in Laravel 10.x to offer additional functionality in the future. Notably, the grammar's raw string value must now be retrieved via the expression'sgetValue(Grammar $grammar)method. Casting an expression to a string using(string)is no longer supported.If your application is manually casting database expressions to strings using
(string)or invoking the__toStringmethod on the expression directly, you should update your code to invoke thegetValuemethod instead:use Illuminate\Support\Facades\DB; $expression = DB::raw('select 1'); $string = $expression->getValue(DB::connection()->getQueryGrammar());
Requirements
PHP >=8.0
Install
Install with Composer:
composer require --dev rector/rector remarkablemark/rector-laravel-database-expressions
Usage
Register rule in rector.php:
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use Remarkablemark\RectorLaravelDatabaseExpressions\LaravelDatabaseExpressionsRector; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/app', __DIR__ . '/bootstrap', __DIR__ . '/config', __DIR__ . '/database', __DIR__ . '/public', __DIR__ . '/resources', __DIR__ . '/routes', __DIR__ . '/storage', __DIR__ . '/tests', ]); $rectorConfig->rule(LaravelDatabaseExpressionsRector::class); };
See the diff:
vendor/bin/rector process --dry-run
Apply the rule:
vendor/bin/rector process
Clear the cache and apply the rule:
vendor/bin/rector process --clear-cache
Rule
Before
DB::select(DB::raw('select 1'));
After
DB::select('select 1');
License
统计信息
- 总下载量: 126
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-20