Skip to content

Commit a039994

Browse files
authored
Merge pull request #166 from bearsunday/php82-readonly-optimization
Optimize for PHP 8.2 readonly classes
2 parents 5ef5a69 + 7445f17 commit a039994

30 files changed

+76
-89
lines changed

rector.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22

33
declare(strict_types=1);
44

5-
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
65
use Rector\Config\RectorConfig;
7-
use Rector\Ray\AnnotationBinding\Rector\ClassMethod\AnnotationBindingRector;
8-
use Rector\Set\ValueObject\LevelSetList;
96

10-
return static function (RectorConfig $rectorConfig): void {
11-
$rectorConfig->paths([
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/demo',
1210
__DIR__ . '/src',
1311
__DIR__ . '/src-annotation',
14-
__DIR__ . '/tests/*/*Test.php',
15-
]);
16-
17-
// register a single rule
18-
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
19-
$rectorConfig->rule(AnnotationBindingRector::class);
20-
// define sets of rules
21-
$rectorConfig->sets([
22-
LevelSetList::UP_TO_PHP_81,
23-
]);
24-
};
12+
__DIR__ . '/src-annotation-deprecated',
13+
__DIR__ . '/tests',
14+
__DIR__ . '/tests-pecl-ext',
15+
__DIR__ . '/tests-php8',
16+
])
17+
// uncomment to reach your current PHP version
18+
->withPhpSets()
19+
->withTypeCoverageLevel(0)
20+
->withDeadCodeLevel(0)
21+
->withCodeQualityLevel(0);

src-annotation-deprecated/CacheVersion.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@
1515
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER), Qualifier]
1616
final class CacheVersion
1717
{
18-
/**
19-
* @var string
20-
*/
21-
public $value;
22-
23-
public function __construct(string $value)
18+
public function __construct(public string $value)
2419
{
25-
$this->value = $value;
2620
}
2721
}

src-annotation/Commands.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use Attribute;
88
use Ray\Di\Di\Qualifier;
99

10-
/**
11-
*/
1210
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
1311
#[Qualifier]
1412
final class Commands

src-annotation/RefreshCache.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
use Attribute;
88
use BEAR\QueryRepository\DonutCommandInterceptor;
99

10-
/**
11-
* @see DonutCommandInterceptor
12-
*/
10+
/** @see DonutCommandInterceptor */
1311
#[Attribute(Attribute::TARGET_METHOD)]
1412
final class RefreshCache
1513
{

src/CacheDependency.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
use function assert;
1111
use function sprintf;
1212

13-
final class CacheDependency implements CacheDependencyInterface
13+
final readonly class CacheDependency implements CacheDependencyInterface
1414
{
1515
public function __construct(
16-
private readonly UriTagInterface $uriTag,
16+
private UriTagInterface $uriTag,
1717
) {
1818
}
1919

src/CacheInterceptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
use const E_USER_WARNING;
1919

20-
final class CacheInterceptor implements MethodInterceptor
20+
final readonly class CacheInterceptor implements MethodInterceptor
2121
{
2222
public function __construct(
23-
private readonly QueryRepositoryInterface $repository,
23+
private QueryRepositoryInterface $repository,
2424
) {
2525
}
2626

src/Cdn/FastlyCachePurger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use BEAR\QueryRepository\PurgerInterface;
99
use Override;
1010

11-
final class FastlyCachePurger implements PurgerInterface
11+
final readonly class FastlyCachePurger implements PurgerInterface
1212
{
13-
public function __construct(private readonly FastlyCachePurgerInterface $fastlyCachePurger)
13+
public function __construct(private FastlyCachePurgerInterface $fastlyCachePurger)
1414
{
1515
}
1616

src/CliHttpCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616

1717
use const PHP_EOL;
1818

19-
final class CliHttpCache implements HttpCacheInterface
19+
final readonly class CliHttpCache implements HttpCacheInterface
2020
{
2121
public function __construct(
22-
private readonly ResourceStorageInterface $storage,
22+
private ResourceStorageInterface $storage,
2323
) {
2424
}
2525

src/CommandInterceptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use Ray\Aop\MethodInterceptor;
1313
use Ray\Aop\MethodInvocation;
1414

15-
final class CommandInterceptor implements MethodInterceptor
15+
final readonly class CommandInterceptor implements MethodInterceptor
1616
{
1717
/** @param CommandInterface[] $commands */
1818
public function __construct(
1919
#[Commands]
20-
private readonly array $commands,
20+
private array $commands,
2121
) {
2222
}
2323

src/CommandsProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use Ray\Di\ProviderInterface;
99

1010
/** @implements ProviderInterface<array<CommandInterface>> */
11-
final class CommandsProvider implements ProviderInterface
11+
final readonly class CommandsProvider implements ProviderInterface
1212
{
1313
public function __construct(
14-
private readonly RefreshSameCommand $refreshSameCommand,
15-
private readonly RefreshAnnotatedCommand $refreshAnnotatedCommand,
14+
private RefreshSameCommand $refreshSameCommand,
15+
private RefreshAnnotatedCommand $refreshAnnotatedCommand,
1616
) {
1717
}
1818

0 commit comments

Comments
 (0)