forked from PGSSoft/HashId
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrector-php82.php
More file actions
85 lines (70 loc) · 3.02 KB
/
rector-php82.php
File metadata and controls
85 lines (70 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php82\Rector\Class_\ReadOnlyClassRector;
use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector;
use Rector\Php82\Rector\New_\FilesystemIteratorSkipDotsRector;
use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNullableTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
/**
* PHP 8.2 Features Configuration
*
* Implements PHP 8.2 modernization rules for the HashId bundle.
* Focuses on readonly classes, type improvements, and modern PHP features.
*
* Applied features:
* - Readonly classes for value objects and immutable classes
* - Null, false, and true as standalone types
* - Sensitive parameter attributes for security-critical data
* - Improved type declarations across the codebase
*/
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);
$rectorConfig->skip([
__DIR__ . '/tests/Fixtures',
__DIR__ . '/tests/App',
__DIR__ . '/var',
__DIR__ . '/vendor',
// Skip DemoController as it's for testing only
__DIR__ . '/src/Controller/DemoController.php',
]);
// PHP 8.2 Feature Rules
$rectorConfig->rules([
// Transform classes with all readonly properties to readonly classes
ReadOnlyClassRector::class,
// Add SensitiveParameter attribute to security-critical parameters
AddSensitiveParameterAttributeRector::class,
// Convert utf8_decode/encode to mb_convert_encoding
Utf8DecodeEncodeToMbConvertEncodingRector::class,
// Use FilesystemIterator::SKIP_DOTS by default
FilesystemIteratorSkipDotsRector::class,
]);
// Additional type improvement rules that complement PHP 8.2
$rectorConfig->rules([
// Add nullable return types based on actual returns
ReturnNullableTypeRector::class,
// Add typed properties from strict constructors
TypedPropertyFromStrictConstructorRector::class,
// Clean up unused private properties
RemoveUnusedPrivatePropertyRector::class,
]);
// Configure sensitive parameters for the bundle
$rectorConfig->ruleWithConfiguration(AddSensitiveParameterAttributeRector::class, [
// Mark salt parameters as sensitive in HashidsConverter
'Pgs\HashIdBundle\ParametersProcessor\Converter\HashidsConverter' => [
'__construct' => [0], // $salt parameter
],
]);
// Import names for cleaner code
$rectorConfig->importNames();
$rectorConfig->importShortClasses(false);
// Performance settings
$rectorConfig->parallel();
$rectorConfig->cacheDirectory(__DIR__ . '/var/cache/rector');
// PHP 8.2 as minimum version
$rectorConfig->phpVersion(\Rector\ValueObject\PhpVersion::PHP_82);
};