Skip to content

Commit 2a5d837

Browse files
committed
feat(guzzle): Add Guzzle configuration for Rector
- Introduced a new guzzle.php file for GuzzleHttp integration. - Configured Rector to utilize StringToClassConstantRector for request options. - Enhanced the handling of class constants for improved code quality.
1 parent 8496097 commit 2a5d837

File tree

16 files changed

+211
-123
lines changed

16 files changed

+211
-123
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ composer require guanguans/rector-rules --dev --ansi -v
2929

3030
* [`Guanguans\RectorRules\Set\SetList::ALL`](src/Set/SetList.php)
3131
* [`Guanguans\RectorRules\Set\SetList::COMMON`](src/Set/SetList.php)
32-
* [`Guanguans\RectorRules\Set\SetList::LARAVEL_80`](src/Set/SetList.php)
33-
* [`Guanguans\RectorRules\Set\SetList::LARAVEL_90`](src/Set/SetList.php)
34-
* [`Guanguans\RectorRules\Set\SetList::LARAVEL_COMMON`](src/Set/SetList.php)
32+
* [`Guanguans\RectorRules\Set\SetList::GUZZLE`](src/Set/SetList.php)
33+
* [`Guanguans\RectorRules\Set\SetList::LARAVEL`](src/Set/SetList.php)
34+
* [`Guanguans\RectorRules\Set\SetList::PEST`](src/Set/SetList.php)
3535
* [`Guanguans\RectorRules\Set\SetList::PHPBENCH`](src/Set/SetList.php)
3636
* [`Guanguans\RectorRules\Set\SetList::PHPSTAN`](src/Set/SetList.php)
3737
* [`Guanguans\RectorRules\Set\SetList::RECTOR`](src/Set/SetList.php)
@@ -47,7 +47,7 @@ use Rector\Config\RectorConfig;
4747

4848
return RectorConfig::configure()
4949
->withSets([
50-
Guanguans\RectorRules\Set\SetList::COMMON,
50+
Guanguans\RectorRules\Set\SetList::ALL,
5151
// ...
5252
])
5353
// ...

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"nette/utils": "^3.2 || ^4.0",
6161
"pestphp/pest": "^1.23 || ^2.0 || ^3.0 || ^4.0",
6262
"php-mock/php-mock-phpunit": "^2.14",
63-
"phpbench/phpbench": "^1.2",
6463
"phpstan/extension-installer": "^1.4",
6564
"phpstan/phpstan": "^2.1",
6665
"phpstan/phpstan-deprecation-rules": "^2.0",

config/set/all.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
$rectorConfig->import(__DIR__.'/../config.php');
2121
$rectorConfig->sets([
2222
SetList::COMMON,
23+
SetList::GUZZLE,
24+
SetList::LARAVEL,
2325
SetList::PEST,
2426
SetList::PHPBENCH,
2527
SetList::PHPSTAN,
2628
SetList::RECTOR,
29+
SetList::SYMFONY,
2730
]);
2831
};

config/set/guzzle.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
5+
declare(strict_types=1);
6+
7+
/**
8+
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*
13+
* @see https://github.com/guanguans/rector-rules
14+
*/
15+
16+
use GuzzleHttp\Client;
17+
use GuzzleHttp\RequestOptions;
18+
use Rector\Config\RectorConfig;
19+
use Rector\Transform\Rector\String_\StringToClassConstantRector;
20+
use Rector\Transform\ValueObject\StringToClassConstant;
21+
22+
return static function (RectorConfig $rectorConfig): void {
23+
if (!class_exists(Client::class)) {
24+
return;
25+
}
26+
27+
$rectorConfig->import(__DIR__.'/../config.php');
28+
29+
$rectorConfig->ruleWithConfiguration(StringToClassConstantRector::class, array_reduce(
30+
[
31+
RequestOptions::class,
32+
],
33+
static fn (array $carry, string $class): array => array_merge(
34+
$carry,
35+
array_map(
36+
static fn (
37+
string $string,
38+
string $constant
39+
): StringToClassConstant => new StringToClassConstant($string, $class, $constant),
40+
$constants = (new ReflectionClass($class))->getConstants(),
41+
array_keys($constants),
42+
),
43+
),
44+
[],
45+
));
46+
};

config/set/laravel.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
5+
declare(strict_types=1);
6+
7+
/**
8+
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*
13+
* @see https://github.com/guanguans/rector-rules
14+
*/
15+
16+
use Carbon\Carbon;
17+
use Illuminate\Foundation\Application;
18+
use Illuminate\Support\Carbon as IlluminateCarbon;
19+
use Illuminate\Support\Str;
20+
use Rector\Config\RectorConfig;
21+
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
22+
use Rector\Renaming\Rector\Name\RenameClassRector;
23+
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
24+
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
25+
use Rector\Transform\ValueObject\FuncCallToStaticCall;
26+
use Rector\Transform\ValueObject\StaticCallToFuncCall;
27+
28+
return static function (RectorConfig $rectorConfig): void {
29+
$rectorConfig->import(__DIR__.'/../config.php');
30+
31+
/**
32+
* @required laravel/framework
33+
*/
34+
if (class_exists(Application::class)) {
35+
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
36+
Carbon::class => IlluminateCarbon::class,
37+
]);
38+
39+
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
40+
'Pest\Faker\fake' => 'fake',
41+
'Pest\Faker\faker' => 'fake',
42+
'faker' => 'fake',
43+
]);
44+
}
45+
46+
/**
47+
* @required illuminate/support
48+
*/
49+
if (method_exists(Str::class, 'of')) {
50+
/**
51+
* @see https://github.com/laravel/framework/commit/d41e88519a6e4203b0986a40c5ac8670a157cf59
52+
*/
53+
\function_exists('str')
54+
? $rectorConfig->ruleWithConfiguration(StaticCallToFuncCallRector::class, [
55+
new StaticCallToFuncCall(Str::class, 'of', 'str'),
56+
])
57+
: $rectorConfig->ruleWithConfiguration(FuncCallToStaticCallRector::class, [
58+
new FuncCallToStaticCall('str', Str::class, 'of'),
59+
]);
60+
}
61+
};

config/set/laravel/laravel-80.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

config/set/laravel/laravel-90.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

config/set/laravel/laravel-common.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

config/set/pest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@
1313
* @see https://github.com/guanguans/rector-rules
1414
*/
1515

16+
use Pest\Expectation;
1617
use Rector\Config\RectorConfig;
1718
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
1819

1920
return static function (RectorConfig $rectorConfig): void {
21+
if (!class_exists(Expectation::class)) {
22+
return;
23+
}
24+
2025
$rectorConfig->import(__DIR__.'/../config.php');
26+
2127
$rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
2228
'test' => 'it',
2329
]);

config/set/phpbench.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414
*/
1515

1616
use PhpBench\Attributes\AbstractMethodsAttribute;
17+
use PhpBench\PhpBench;
1718
use Rector\Config\RectorConfig;
1819
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
1920
use Rector\Php80\ValueObject\AnnotationToAttribute;
2021
use Rector\ValueObject\PhpVersion;
2122

2223
return static function (RectorConfig $rectorConfig): void {
24+
if (!class_exists(PhpBench::class)) {
25+
return;
26+
}
27+
2328
$rectorConfig->import(__DIR__.'/../config.php');
2429

2530
if (\PHP_VERSION_ID >= PhpVersion::PHP_80 && class_exists(AbstractMethodsAttribute::class)) {
2631
$reflectionClass = new ReflectionClass(AbstractMethodsAttribute::class);
27-
2832
$rectorConfig->ruleWithConfiguration(
2933
AnnotationToAttributeRector::class,
3034
array_reduce(

0 commit comments

Comments
 (0)