Skip to content

Commit bf54529

Browse files
[1.x] Refactor to use first-class callable (#315)
* refactor to use first-class callables Signed-off-by: Pushpak Chhajed <[email protected]> * fix test Signed-off-by: Pushpak Chhajed <[email protected]> * update roster package Signed-off-by: Pushpak Chhajed <[email protected]> * Centralize table validation logic in `isTableProvided` method Signed-off-by: Pushpak Chhajed <[email protected]> * isTableProvided -> hasTable --------- Signed-off-by: Pushpak Chhajed <[email protected]> Co-authored-by: Joe Tannenbaum <[email protected]>
1 parent dd0f3bc commit bf54529

File tree

12 files changed

+23
-17
lines changed

12 files changed

+23
-17
lines changed

rector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
declare(strict_types=1);
44

55
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
6+
use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
67
use Rector\Config\RectorConfig;
78
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
8-
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;
99
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
1010

1111
return RectorConfig::configure()
@@ -17,13 +17,14 @@
1717
ReadOnlyPropertyRector::class,
1818
EncapsedStringsToSprintfRector::class,
1919
DisallowedEmptyRuleFixerRector::class,
20-
BooleanInBooleanNotRuleFixerRector::class,
20+
FunctionLikeToFirstClassCallableRector::class => [
21+
__DIR__.'src/Install/CodeEnvironmentsDetector.php',
22+
],
2123
])
2224
->withPreparedSets(
2325
deadCode: true,
2426
codeQuality: true,
2527
codingStyle: true,
2628
typeDeclarations: true,
2729
earlyReturn: true,
28-
strictBooleans: true,
2930
)->withPhpSets(php81: true);

src/BoostServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function boot(Router $router): void
7474

7575
if (config('boost.browser_logs_watcher', true)) {
7676
$this->registerBrowserLogger();
77-
$this->callAfterResolving('blade.compiler', fn (BladeCompiler $bladeCompiler) => $this->registerBladeDirectives($bladeCompiler));
77+
$this->callAfterResolving('blade.compiler', $this->registerBladeDirectives(...));
7878
$this->hookIntoResponses($router);
7979
}
8080
}

src/Install/Cli/DisplayHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function grid(array $items, int $maxWidth = 80): void
8787
}
8888

8989
$maxWidth -= 2; // account for grid margins
90-
$maxItemLength = max(array_map('mb_strlen', $items));
90+
$maxItemLength = max(array_map(mb_strlen(...), $items));
9191
$cellWidth = $maxItemLength + self::GRID_CELL_PADDING;
9292
$cellsPerRow = max(1, (int) floor(($maxWidth - 1) / ($cellWidth + 1)));
9393
$rows = array_chunk($items, $cellsPerRow);

src/Install/Detection/DetectionStrategyFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function make(string|array $type, array $config = []): DetectionStrategy
2222
{
2323
if (is_array($type)) {
2424
return new CompositeDetectionStrategy(
25-
array_map(fn ($singleType): \Laravel\Boost\Install\Contracts\DetectionStrategy => $this->make($singleType, $config), $type)
25+
array_map(fn (string|array $singleType): \Laravel\Boost\Install\Contracts\DetectionStrategy => $this->make($singleType, $config), $type)
2626
);
2727
}
2828

src/Mcp/Tools/DatabaseSchema/DatabaseSchemaDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ abstract class DatabaseSchemaDriver
88
{
99
public function __construct(protected $connection = null) {}
1010

11+
protected function hasTable(?string $table): bool
12+
{
13+
return ! in_array($table, [null, '', '0'], true);
14+
}
15+
1116
abstract public function getViews(): array;
1217

1318
abstract public function getStoredProcedures(): array;

src/Mcp/Tools/DatabaseSchema/MySQLSchemaDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getFunctions(): array
4343
public function getTriggers(?string $table = null): array
4444
{
4545
try {
46-
if ($table !== null && $table !== '' && $table !== '0') {
46+
if ($this->hasTable($table)) {
4747
return DB::connection($this->connection)->select('SHOW TRIGGERS WHERE `Table` = ?', [$table]);
4848
}
4949

src/Mcp/Tools/DatabaseSchema/PostgreSQLSchemaDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function getTriggers(?string $table = null): array
6060
FROM information_schema.triggers
6161
WHERE trigger_schema = current_schema()
6262
';
63-
if ($table !== null && $table !== '' && $table !== '0') {
63+
if ($this->hasTable($table)) {
6464
$sql .= ' AND event_object_table = ?';
6565

6666
return DB::connection($this->connection)->select($sql, [$table]);

src/Mcp/Tools/DatabaseSchema/SQLiteSchemaDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getTriggers(?string $table = null): array
3636
{
3737
try {
3838
$sql = "SELECT name, sql FROM sqlite_master WHERE type = 'trigger'";
39-
if ($table !== null && $table !== '' && $table !== '0') {
39+
if ($this->hasTable($table)) {
4040
$sql .= ' AND tbl_name = ?';
4141

4242
return DB::connection($this->connection)->select($sql, [$table]);

src/Mcp/Tools/ListAvailableEnvVars.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function handle(Request $request): Response
6060
return Response::error('Failed to parse .env file');
6161
}
6262

63-
$envVars = array_map('trim', $matches[1]);
63+
$envVars = array_map(trim(...), $matches[1]);
6464

6565
sort($envVars);
6666

src/Mcp/Tools/SearchDocs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function handle(Request $request): Response|Generator
5454
$packagesFilter = $request->get('packages');
5555

5656
$queries = array_filter(
57-
array_map('trim', $request->get('queries')),
57+
array_map(trim(...), $request->get('queries')),
5858
fn (string $query): bool => $query !== '' && $query !== '*'
5959
);
6060

0 commit comments

Comments
 (0)