From 5e4215f43be70cfe249f4441dd55a0c4aa99b076 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 14 Dec 2024 23:43:13 +0100 Subject: [PATCH 1/4] bump deps --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 0963f3cdb..e2cc8604a 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "livewire/livewire": "^3.5", "nesbot/carbon": "^3.8", "nikic/php-parser": "^5.0", - "rector/rector": "dev-main as 1.2.9", + "rector/rector": "dev-main as 2.0", "samsonasik/array-lookup": "^1.6", "symfony/filesystem": "^7.1", "symfony/uid": "^7.1", @@ -19,16 +19,16 @@ "symplify/vendor-patches": "^11.3" }, "require-dev": { - "barryvdh/laravel-ide-helper": "^3.1", - "driftingly/rector-laravel": "^1.2.1", + "barryvdh/laravel-ide-helper": "^3.2", + "driftingly/rector-laravel": "^2.0", "nette/robot-loader": "^4.0", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.0", "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "11.4.0", "rector/swiss-knife": "^1.0", - "symplify/easy-coding-standard": "^12.3", - "tomasvotruba/class-leak": "^1.1" + "symplify/easy-coding-standard": "^12.4", + "tomasvotruba/class-leak": "^2.0" }, "autoload": { "psr-4": { From 1969a1e5d77e75ad55ad30c46edb73638090f4b1 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 15 Dec 2024 01:37:36 +0100 Subject: [PATCH 2/4] [post] rector 2 --- .../2024-12-12-5-new-features-in-rector-20.md | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md diff --git a/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md b/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md new file mode 100644 index 000000000..8503185b9 --- /dev/null +++ b/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md @@ -0,0 +1,166 @@ +--- +id: 74 +title: "5 New Features in Rector 2.0" +perex: | + Rector 2 is out! We've upgraded to PHPStan 2 and PHP-Parser 5. Based on testing on a couple huge legacy projects, Rector now runs **10-15 %** faster. + + We've also managed to fit in couple new features. +--- + +Let's take a look at what's new. + +
+ +## 1. The `--only` Option to run 1 Rule + +At the moment, the Rector repository has a `rector.php` config that enables runs 350+ rules. What if we add a single custom rule and want to run only that one? We'd have to comment out all other rules, run Rector, and then uncomment them back. That's a lot of manual work, right? + +
+ +**Now we can use the `--only` option to run only a single rule**: + +```bash +vendor/bin/rector process src --only="Utils\Rector\MoveTraitsToConstructorRector" +``` + +It's was a tough challenge to make all quotes and slashes in CLI work across all operating systems. + +Thanks to [Christian Weiske](https://github.com/rectorphp/rector-src/pull/6441) who's done a great job on this feature. + +
+ +## 2. Introducing Composer-based sets + +In the wild, the vendor-sets like Symfony, Twig, Laravel or Doctrine, have many sets - each containing a group or rules for specific version. Symfony has over 20 sets, but let's look at simpler example - Twig: + +```php +use Rector\Config\RectorConfig; + +return RectorConfig::configure() + ->withSets([ + \Rector\Symfony\Set\TwigSetList::TWIG_112, + \Rector\Symfony\Set\TwigSetList::TWIG_127, + \Rector\Symfony\Set\TwigSetList::TWIG_134, + \Rector\Symfony\Set\TwigSetList::TWIG_20, + \Rector\Symfony\Set\TwigSetList::TWIG_24, + ]) +``` + +
+ +This is wrong for many reasons. It can lead to: + +* bloated `rector.php` file +* missed new set, as we have to always add new sets as they're published +* conflicting changes as version 2.4 can remove something added in version 1.12, many years apart + +
+ +Instead, **Rector should be able to pick up version from installed version, and provide only relevant rules**. + +Fully automated, like following: + +```php +return RectorConfig::configure() + ->withComposerBased(twig: true) +``` + +Currently we provide `twig`, `doctrine` and `phpunit` composer-based sets. + +If you want to **know how it works behind the scenes**, check [this dedicated post](/blog/introducing-composer-version-based-sets). + +
+ +## 3. Polyfill Packages by Default + +We had a special configuration to enable [polyfill packages](https://github.com/symfony/polyfill). That way we can get PHP 8.x features early on PHP 7.x codebase. Yet, not many people knew about it and missed it. Also, polyfill packages are already defined in the `composer.json`, so it doesn't make sense to "enable" them again `rector.php`. + +We've decided to include polyfills by default when `->withPhpSets()` is called. So you can drop the extra method: + +```diff + use Rector\Config\RectorConfig; + + return RectorConfig::configure() +- ->withPhpPolyfill() + ->withPhpSets(); +``` + +It works for all `->withPhp*Sets()` too. + +
+ +## 4. Smarter Annotations to Attributes sets + +We're proving [annotations to attributes upgrade](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes) since PHP 8.0 day one. You can enable them in `rector.php` easily: + +```php +use Rector\Config\RectorConfig; + +return RectorConfig::configure() + ->withAttributesSets(symfony: true, phpunit: true, doctrine: true); +``` + +
+ +In reality, some packages add attribute support a bit later. E.g. Rector 2 ships with [Behat attributes](https://github.com/rectorphp/rector-src/pull/6510) contributed by [Carlos Granados](https://github.com/carlos-granados). To use them in our project, we'd have to change the config: + +```diff + use Rector\Config\RectorConfig; + + return RectorConfig::configure() +- ->withAttributesSets(symfony: true, phpunit: true, doctrine: true); ++ ->withAttributesSets(symfony: true, phpunit: true, doctrine: true, behat: true); +``` + +
+ +But who has time to keep checking if this or that package has new attribute sets. Instead, **make the method empty**: + +```diff + use Rector\Config\RectorConfig; + + return RectorConfig::configure() +- ->withAttributesSets(symfony: true, phpunit: true, doctrine: true); ++ ->withAttributesSets(); +``` + +Now Rector will pick up all attribute sets automatically. + +
+ +Also, Rector will now check if the attribute **actually exists before it adds it**. E.g. `#[Route]` attribute was not added until Symfony 5.2. If you're running Symfony 5.1, Rector will not make any changes to your code. + + +
+ +## 5. Leaner Custom Rules + +Last but not least, we've collected feedback from custom rule creators. We also create many custom rules for our clients. Some of them are temporary, other are fixing simple elements. Still, we always have to fill `getRuleDefinition()` with dummy data, to make Rector happy. In reality, this method is used only by Rector core rules for [Find rule](https://getrector.com/find-rule) page. + +Saying that, we no longer need to write tedious `getRuleDefinition()`. These methods can be finally dropped: + +```diff + use Rector\Rector\AbstractRector; +-use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; +-use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; + + final class SimpleRector extends AbstractRector + { +- public function getRuleDefinition(): RuleDefinition +- { +- return new RuleDefinition('// @todo fill the description', [ +- new CodeSample('...', '...'), +- ]); +- } + + // valuable code starts here + } +``` + + +See the [upgrade guide](https://github.com/rectorphp/rector/blob/main/UPGRADING.md) for full details. + +
+ +Happy coding! + From 05ade3e26d6bd144fdfa2e894d2055e0d564bb86 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 15 Dec 2024 01:37:46 +0100 Subject: [PATCH 3/4] bump to PHP 8.2 --- rector.php | 2 ++ routes/web.php | 4 +--- src/Controller/FindRuleController.php | 2 +- .../Stats/FindRuleStatsController.php | 4 +--- src/DemoRunner.php | 10 ++++----- .../DocumentationMenuFactory.php | 2 +- src/Documentation/DocumentationMenuItem.php | 2 +- .../DocumentationMenuItemFactory.php | 2 +- src/Entity/Post.php | 22 +++++++++---------- src/EntityFactory/PostFactory.php | 4 ++-- src/FileSystem/RectorFinder.php | 4 ++-- .../LinkFactory/FixtureLinkFactory.php | 6 ++--- .../LinkFactory/IssueLinkFactory.php | 4 ++-- src/PhpParser/SimplePhpParser.php | 2 +- src/Providers/AppServiceProvider.php | 4 +--- src/Repository/RectorRunRepository.php | 4 ++-- .../ConfiguredDiffSamplesFactory.php | 11 +++++----- src/RuleFilter/Markdown/MarkdownDiffer.php | 4 ++-- .../ConstantToValueNodeVisitor.php | 2 +- src/RuleFilter/RuleFilter.php | 8 +++---- src/RuleFilter/ValueObject/RuleMetadata.php | 8 +++---- src/Utils/Arrays.php | 4 +--- src/Utils/ClickablePrinterBuilder.php | 8 +++---- src/Validation/Rules/HasRectorRule.php | 2 +- src/Validation/Rules/ShortPhpConfigRule.php | 4 ++-- src/Validation/Rules/ShortPhpContentsRule.php | 4 ++-- .../Rules/ValidAndSafePhpSyntaxRule.php | 2 +- src/ValueObject/AppliedRule.php | 6 ++--- 28 files changed, 66 insertions(+), 75 deletions(-) diff --git a/rector.php b/rector.php index 65a3d8ddd..41c20f917 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,8 @@ typeDeclarations: true, rectorPreset: true, ) + ->withPhpSets() + ->withAttributesSets() ->withSkip([ RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class => [ // metadata -> datum false positive diff --git a/routes/web.php b/routes/web.php index 8e19dbd38..f38c25677 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,9 +38,7 @@ Route::get('documentation/{section?}', DocumentationController::class); Route::get('blog', BlogController::class); -Route::get('book', function () { - return redirect()->to('https://leanpub.com/rector-the-power-of-automated-refactoring'); -}); +Route::get('book', fn() => redirect()->to('https://leanpub.com/rector-the-power-of-automated-refactoring')); Route::get('contact', ContactController::class); Route::get('hire-team', HireTeamController::class); diff --git a/src/Controller/FindRuleController.php b/src/Controller/FindRuleController.php index eb0e39d68..8e0e40557 100644 --- a/src/Controller/FindRuleController.php +++ b/src/Controller/FindRuleController.php @@ -11,7 +11,7 @@ final class FindRuleController extends Controller { public function __construct( - private RectorFinder $rectorFinder + private readonly RectorFinder $rectorFinder ) { } diff --git a/src/Controller/Stats/FindRuleStatsController.php b/src/Controller/Stats/FindRuleStatsController.php index 7ba332cb7..27c9ead5e 100644 --- a/src/Controller/Stats/FindRuleStatsController.php +++ b/src/Controller/Stats/FindRuleStatsController.php @@ -56,9 +56,7 @@ public function __invoke(): View */ private function getArrayFlattenKey(array $items, string $keyName): array { - $items = array_map(function (array $item) use ($keyName) { - return $item[$keyName]; - }, $items); + $items = array_map(fn(array $item) => $item[$keyName], $items); // remove empty ones return array_filter($items); diff --git a/src/DemoRunner.php b/src/DemoRunner.php index 1c0183250..cb5b607df 100644 --- a/src/DemoRunner.php +++ b/src/DemoRunner.php @@ -21,7 +21,7 @@ /** * @see \App\Tests\DemoRunnerTest */ -final class DemoRunner +final readonly class DemoRunner { /** * @var string @@ -38,12 +38,12 @@ final class DemoRunner */ private const EXIT_CODE_SUCCESS = 0; - private readonly string $demoDir; + private string $demoDir; public function __construct( - private readonly ErrorMessageNormalizer $errorMessageNormalizer, - private readonly Filesystem $filesystem, - private readonly RectorProcessFactory $rectorProcessFactory, + private ErrorMessageNormalizer $errorMessageNormalizer, + private Filesystem $filesystem, + private RectorProcessFactory $rectorProcessFactory, ) { $this->demoDir = __DIR__ . '/../storage/demo'; } diff --git a/src/Documentation/DocumentationMenuFactory.php b/src/Documentation/DocumentationMenuFactory.php index 51f1afb5f..37402a9aa 100644 --- a/src/Documentation/DocumentationMenuFactory.php +++ b/src/Documentation/DocumentationMenuFactory.php @@ -9,7 +9,7 @@ /** * @see \App\Tests\Documentation\DocumentationMenuFactoryTest */ -final class DocumentationMenuFactory +final readonly class DocumentationMenuFactory { public function __construct( private DocumentationMenuItemFactory $documentationMenuItemFactory diff --git a/src/Documentation/DocumentationMenuItem.php b/src/Documentation/DocumentationMenuItem.php index dde33a217..1399f9efd 100644 --- a/src/Documentation/DocumentationMenuItem.php +++ b/src/Documentation/DocumentationMenuItem.php @@ -4,7 +4,7 @@ namespace App\Documentation; -final class DocumentationMenuItem +final readonly class DocumentationMenuItem { public function __construct( private string $href, diff --git a/src/Documentation/DocumentationMenuItemFactory.php b/src/Documentation/DocumentationMenuItemFactory.php index cc745ad75..c6016e301 100644 --- a/src/Documentation/DocumentationMenuItemFactory.php +++ b/src/Documentation/DocumentationMenuItemFactory.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Routing\UrlGenerator; use Illuminate\Routing\Controller; -final class DocumentationMenuItemFactory +final readonly class DocumentationMenuItemFactory { public function __construct( private UrlGenerator $urlGenerator diff --git a/src/Entity/Post.php b/src/Entity/Post.php index e92d92f6e..3eb0a3c26 100644 --- a/src/Entity/Post.php +++ b/src/Entity/Post.php @@ -7,19 +7,19 @@ use App\Controller\Blog\PostController; use DateTimeInterface; -final class Post +final readonly class Post { public function __construct( - private readonly int $id, - private readonly string $title, - private readonly string $slug, - private readonly DateTimeInterface $dateTime, - private readonly string $perex, - private readonly string $contents, - private readonly string $author, - private readonly ?DateTimeInterface $updatedAt = null, - private readonly ?string $updatedMessage = null, - private readonly ?string $sinceRector = null + private int $id, + private string $title, + private string $slug, + private DateTimeInterface $dateTime, + private string $perex, + private string $contents, + private string $author, + private ?DateTimeInterface $updatedAt = null, + private ?string $updatedMessage = null, + private ?string $sinceRector = null ) { } diff --git a/src/EntityFactory/PostFactory.php b/src/EntityFactory/PostFactory.php index de86763e9..11ceddb9d 100644 --- a/src/EntityFactory/PostFactory.php +++ b/src/EntityFactory/PostFactory.php @@ -14,7 +14,7 @@ use Symfony\Component\Yaml\Yaml; use Webmozart\Assert\Assert; -final class PostFactory +final readonly class PostFactory { /** * @var string @@ -27,7 +27,7 @@ final class PostFactory private const CONFIG_CONTENT_REGEX = '#^\s*' . self::SLASHES_WITH_SPACES_REGEX . '?(?.*?)' . self::SLASHES_WITH_SPACES_REGEX . '(?.*?)$#s'; public function __construct( - private readonly PathAnalyzer $pathAnalyzer, + private PathAnalyzer $pathAnalyzer, ) { } diff --git a/src/FileSystem/RectorFinder.php b/src/FileSystem/RectorFinder.php index 5329566ee..45dd6fcb3 100644 --- a/src/FileSystem/RectorFinder.php +++ b/src/FileSystem/RectorFinder.php @@ -15,7 +15,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; -final class RectorFinder +final readonly class RectorFinder { /** * @var string[] @@ -28,7 +28,7 @@ final class RectorFinder ]; public function __construct( - private readonly RectorSetsTreeProvider $rectorSetsTreeProvider, + private RectorSetsTreeProvider $rectorSetsTreeProvider, ) { } diff --git a/src/GitHubMagicLink/LinkFactory/FixtureLinkFactory.php b/src/GitHubMagicLink/LinkFactory/FixtureLinkFactory.php index 3960c516b..4dea33e46 100644 --- a/src/GitHubMagicLink/LinkFactory/FixtureLinkFactory.php +++ b/src/GitHubMagicLink/LinkFactory/FixtureLinkFactory.php @@ -12,7 +12,7 @@ /** * @see \App\GitHubMagicLink\Twig\FixtureLinkTwigExtension */ -final class FixtureLinkFactory +final readonly class FixtureLinkFactory { /** * @var string @@ -36,8 +36,8 @@ final class FixtureLinkFactory private const DOWNGRADE_PACKAGE_PREFIX = 'DowngradePhp'; public function __construct( - private readonly FixtureBodyFactory $fixtureBodyFactory, - private readonly PullRequestDescriptionFactory $pullRequestDescriptionFactory + private FixtureBodyFactory $fixtureBodyFactory, + private PullRequestDescriptionFactory $pullRequestDescriptionFactory ) { } diff --git a/src/GitHubMagicLink/LinkFactory/IssueLinkFactory.php b/src/GitHubMagicLink/LinkFactory/IssueLinkFactory.php index 033c82614..681db188a 100644 --- a/src/GitHubMagicLink/LinkFactory/IssueLinkFactory.php +++ b/src/GitHubMagicLink/LinkFactory/IssueLinkFactory.php @@ -8,7 +8,7 @@ use App\GitHubMagicLink\BodyFactory\IssueBodyFactory; use App\ValueObject\AppliedRule; -final class IssueLinkFactory +final readonly class IssueLinkFactory { /** * @var string @@ -16,7 +16,7 @@ final class IssueLinkFactory private const BASE_URL = 'https://github.com/rectorphp/rector/issues/new?labels=bug&template=1_Bug_report.md'; public function __construct( - private readonly IssueBodyFactory $issueBodyFactory + private IssueBodyFactory $issueBodyFactory ) { } diff --git a/src/PhpParser/SimplePhpParser.php b/src/PhpParser/SimplePhpParser.php index bb10c6110..bf368e7b1 100644 --- a/src/PhpParser/SimplePhpParser.php +++ b/src/PhpParser/SimplePhpParser.php @@ -16,7 +16,7 @@ use PhpParser\Parser; use PhpParser\ParserFactory; -final class SimplePhpParser +final readonly class SimplePhpParser { private Parser $phpParser; diff --git a/src/Providers/AppServiceProvider.php b/src/Providers/AppServiceProvider.php index 836f35eda..99c75ea89 100644 --- a/src/Providers/AppServiceProvider.php +++ b/src/Providers/AppServiceProvider.php @@ -21,9 +21,7 @@ public function register(): void { $this->app->singleton(RectorSetsTreeProvider::class); - $this->app->singleton(SymfonyStyle::class, function (): SymfonyStyle { - return new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()); - }); + $this->app->singleton(SymfonyStyle::class, fn(): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())); $this->app->singleton(MarkdownDiffer::class, function (): MarkdownDiffer { // this is required to show full diffs from start to end diff --git a/src/Repository/RectorRunRepository.php b/src/Repository/RectorRunRepository.php index b645aa95f..95ac857ec 100644 --- a/src/Repository/RectorRunRepository.php +++ b/src/Repository/RectorRunRepository.php @@ -9,7 +9,7 @@ use Nette\Utils\FileSystem; use Symfony\Component\Uid\Uuid; -final class RectorRunRepository +final readonly class RectorRunRepository { /** * @var string @@ -17,7 +17,7 @@ final class RectorRunRepository private const TABLE_FILE = 'rector_runs.json'; // @see https://github.com/donjajo/php-jsondb - private readonly JSONDB $jsondb; + private JSONDB $jsondb; public function __construct() { diff --git a/src/RuleFilter/ConfiguredDiffSamplesFactory.php b/src/RuleFilter/ConfiguredDiffSamplesFactory.php index 7a1563c45..02faf41cf 100644 --- a/src/RuleFilter/ConfiguredDiffSamplesFactory.php +++ b/src/RuleFilter/ConfiguredDiffSamplesFactory.php @@ -63,13 +63,12 @@ private function resolveConfiguredCodeSampleNews(array $stmts): array $nodeFinder = new NodeFinder(); /** @var New_[] $configuredCodeSampleNews */ - $configuredCodeSampleNews = $nodeFinder->find($stmts, function (Node $node): bool { + $configuredCodeSampleNews = $nodeFinder->find($stmts, fn(Node $node): bool => // we look for "new ConfiguredCodeSample()" - return $this->isNewWithClassName( - $node, - 'Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample' - ); - }); + $this->isNewWithClassName( + $node, + 'Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample' + )); return $configuredCodeSampleNews; } diff --git a/src/RuleFilter/Markdown/MarkdownDiffer.php b/src/RuleFilter/Markdown/MarkdownDiffer.php index 51ba9653c..f91457d0e 100644 --- a/src/RuleFilter/Markdown/MarkdownDiffer.php +++ b/src/RuleFilter/Markdown/MarkdownDiffer.php @@ -12,7 +12,7 @@ * * @see \App\Tests\RuleFilter\Markdown\MarkdownDifferTest */ -final class MarkdownDiffer +final readonly class MarkdownDiffer { /** * @var string @@ -27,7 +27,7 @@ final class MarkdownDiffer private const SPACE_AND_NEWLINE_REGEX = '#( ){1,}\n#'; public function __construct( - private readonly Differ $differ, + private Differ $differ, ) { } diff --git a/src/RuleFilter/PhpParser/NodeVisitor/ConstantToValueNodeVisitor.php b/src/RuleFilter/PhpParser/NodeVisitor/ConstantToValueNodeVisitor.php index bbf27087c..ce2587907 100644 --- a/src/RuleFilter/PhpParser/NodeVisitor/ConstantToValueNodeVisitor.php +++ b/src/RuleFilter/PhpParser/NodeVisitor/ConstantToValueNodeVisitor.php @@ -14,7 +14,7 @@ final class ConstantToValueNodeVisitor extends NodeVisitorAbstract { public function __construct( - private string $ruleClass + private readonly string $ruleClass ) { } diff --git a/src/RuleFilter/RuleFilter.php b/src/RuleFilter/RuleFilter.php index fa115c0b4..56c03886e 100644 --- a/src/RuleFilter/RuleFilter.php +++ b/src/RuleFilter/RuleFilter.php @@ -9,7 +9,7 @@ use App\RuleFilter\ValueObject\RuleMetadata; use App\Sets\RectorSetsTreeProvider; -final class RuleFilter +final readonly class RuleFilter { /** * @var int @@ -17,7 +17,7 @@ final class RuleFilter private const MAX_RESULTS = 10; public function __construct( - private readonly MatchingScoreResolver $matchingScoreResolver, + private MatchingScoreResolver $matchingScoreResolver, ) { } @@ -65,9 +65,7 @@ private function filterByQuery(array $ruleMetadatas, ?string $query): array // sort by score usort( $filteredRuleMetadatas, - function (RuleMetadata $firstRuleMetadata, RuleMetadata $secondRuleMetadata): int { - return $secondRuleMetadata->getFilterScore() <=> $firstRuleMetadata->getFilterScore(); - } + fn(RuleMetadata $firstRuleMetadata, RuleMetadata $secondRuleMetadata): int => $secondRuleMetadata->getFilterScore() <=> $firstRuleMetadata->getFilterScore() ); return $filteredRuleMetadatas; diff --git a/src/RuleFilter/ValueObject/RuleMetadata.php b/src/RuleFilter/ValueObject/RuleMetadata.php index d7ed732af..3983d5e74 100644 --- a/src/RuleFilter/ValueObject/RuleMetadata.php +++ b/src/RuleFilter/ValueObject/RuleMetadata.php @@ -24,11 +24,11 @@ final class RuleMetadata * @param CodeSampleInterface[] $codeSamples */ public function __construct( - private string $ruleClass, - private string $description, + private readonly string $ruleClass, + private readonly string $description, private array $codeSamples, - private array $sets, - private string $rectorRuleFilePath + private readonly array $sets, + private readonly string $rectorRuleFilePath ) { Assert::isAOf($ruleClass, RectorInterface::class); Assert::allIsAOf($sets, RectorSet::class); diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php index 1b3abfcac..c20ff6085 100644 --- a/src/Utils/Arrays.php +++ b/src/Utils/Arrays.php @@ -16,8 +16,6 @@ public static function groupToCount(array $items, int $requiredCount = 1): array arsort($itemsToValues); // at least twice - return array_filter($itemsToValues, function (int $count) use ($requiredCount): bool { - return $count > $requiredCount; - }); + return array_filter($itemsToValues, fn(int $count): bool => $count > $requiredCount); } } diff --git a/src/Utils/ClickablePrinterBuilder.php b/src/Utils/ClickablePrinterBuilder.php index 2876be9e9..2d2de220a 100644 --- a/src/Utils/ClickablePrinterBuilder.php +++ b/src/Utils/ClickablePrinterBuilder.php @@ -29,7 +29,7 @@ * @api used in bin * @see \App\Ast\PhpParser\ClickablePrinter */ -final class ClickablePrinterBuilder +final readonly class ClickablePrinterBuilder { /** * @var string @@ -42,9 +42,9 @@ final class ClickablePrinterBuilder private const ACTIVE_NODE_ID = 'activeNodeId'; public function __construct( - private readonly SimplePhpParser $simplePhpParser, - private readonly BuilderFactory $builderFactory, - private readonly ClickablePrinterNodeFactory $clickablePrinterNodeFactory + private SimplePhpParser $simplePhpParser, + private BuilderFactory $builderFactory, + private ClickablePrinterNodeFactory $clickablePrinterNodeFactory ) { } diff --git a/src/Validation/Rules/HasRectorRule.php b/src/Validation/Rules/HasRectorRule.php index da0b098dc..6f0691111 100644 --- a/src/Validation/Rules/HasRectorRule.php +++ b/src/Validation/Rules/HasRectorRule.php @@ -24,7 +24,7 @@ final class HasRectorRule implements ValidationRule public function validate(string $attribute, mixed $value, Closure $fail): void { // dummy check for custom rule request - if (str_contains($value, AbstractRector::class)) { + if (str_contains((string) $value, AbstractRector::class)) { return; } diff --git a/src/Validation/Rules/ShortPhpConfigRule.php b/src/Validation/Rules/ShortPhpConfigRule.php index 18c342e82..84514d28d 100644 --- a/src/Validation/Rules/ShortPhpConfigRule.php +++ b/src/Validation/Rules/ShortPhpConfigRule.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Translation\PotentiallyTranslatedString; -final class ShortPhpConfigRule implements ValidationRule +final readonly class ShortPhpConfigRule implements ValidationRule { /** * @var int @@ -16,7 +16,7 @@ final class ShortPhpConfigRule implements ValidationRule private const INPUT_LINES_LIMIT = 200; public function __construct( - private readonly ShortPhpLines $shortPhpLines + private ShortPhpLines $shortPhpLines ) { } diff --git a/src/Validation/Rules/ShortPhpContentsRule.php b/src/Validation/Rules/ShortPhpContentsRule.php index 684a33b09..0a0ada977 100644 --- a/src/Validation/Rules/ShortPhpContentsRule.php +++ b/src/Validation/Rules/ShortPhpContentsRule.php @@ -8,7 +8,7 @@ use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Translation\PotentiallyTranslatedString; -final class ShortPhpContentsRule implements ValidationRule +final readonly class ShortPhpContentsRule implements ValidationRule { /** * @var int @@ -16,7 +16,7 @@ final class ShortPhpContentsRule implements ValidationRule private const INPUT_LINES_LIMIT = 100; public function __construct( - private readonly ShortPhpLines $shortPhpLines + private ShortPhpLines $shortPhpLines ) { } diff --git a/src/Validation/Rules/ValidAndSafePhpSyntaxRule.php b/src/Validation/Rules/ValidAndSafePhpSyntaxRule.php index 89f48c5c9..3dff8de22 100644 --- a/src/Validation/Rules/ValidAndSafePhpSyntaxRule.php +++ b/src/Validation/Rules/ValidAndSafePhpSyntaxRule.php @@ -16,7 +16,7 @@ use PhpParser\Parser; use PhpParser\ParserFactory; -final class ValidAndSafePhpSyntaxRule implements ValidationRule +final readonly class ValidAndSafePhpSyntaxRule implements ValidationRule { /** * @see https://regex101.com/r/GzUnSz/1 diff --git a/src/ValueObject/AppliedRule.php b/src/ValueObject/AppliedRule.php index 632dd1d60..5e341d098 100644 --- a/src/ValueObject/AppliedRule.php +++ b/src/ValueObject/AppliedRule.php @@ -7,12 +7,12 @@ use App\Exception\ShouldNotHappenException; use Nette\Utils\Strings; -final class AppliedRule +final readonly class AppliedRule { - private readonly string $shortRectorClass; + private string $shortRectorClass; public function __construct( - private readonly string $rectorClass + private string $rectorClass ) { $shortRectorClassName = Strings::after($rectorClass, '\\', -1); if (! is_string($shortRectorClassName)) { From b27137665c1e86e55e9ba402d024971dea1b3737 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 15 Dec 2024 01:37:51 +0100 Subject: [PATCH 4/4] gram --- composer.lock | 427 ++++++++++++------ .../2024-12-12-5-new-features-in-rector-20.md | 37 +- .../Stats/FindRuleStatsController.php | 2 +- src/FileSystem/RectorFinder.php | 10 +- src/Providers/AppServiceProvider.php | 5 +- .../ConfiguredDiffSamplesFactory.php | 8 +- src/RuleFilter/RuleFilter.php | 2 +- src/Utils/Arrays.php | 2 +- 8 files changed, 335 insertions(+), 158 deletions(-) diff --git a/composer.lock b/composer.lock index 6eff7cf98..4c8ef3847 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9f9bab49d37d195cc45711182b9b2ff2", + "content-hash": "2d40e1717e327a44c3dcd0e7f8c95080", "packages": [ { "name": "brick/math", @@ -1215,16 +1215,16 @@ }, { "name": "laravel/framework", - "version": "v11.34.2", + "version": "v11.35.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "865da6d73dd353f07a7bcbd778c55966a620121f" + "reference": "dcfa130ede1a6fa4343dc113410963e791ad34fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/865da6d73dd353f07a7bcbd778c55966a620121f", - "reference": "865da6d73dd353f07a7bcbd778c55966a620121f", + "url": "https://api.github.com/repos/laravel/framework/zipball/dcfa130ede1a6fa4343dc113410963e791ad34fb", + "reference": "dcfa130ede1a6fa4343dc113410963e791ad34fb", "shasum": "" }, "require": { @@ -1248,6 +1248,7 @@ "league/commonmark": "^2.2.1", "league/flysystem": "^3.25.1", "league/flysystem-local": "^3.25.1", + "league/uri": "^7.5.1", "monolog/monolog": "^3.0", "nesbot/carbon": "^2.72.2|^3.4", "nunomaduro/termwind": "^2.0", @@ -1331,9 +1332,9 @@ "league/flysystem-read-only": "^3.25.1", "league/flysystem-sftp-v3": "^3.25.1", "mockery/mockery": "^1.6.10", - "nyholm/psr7": "^1.2", "orchestra/testbench-core": "^9.6", "pda/pheanstalk": "^5.0.6", + "php-http/discovery": "^1.15", "phpstan/phpstan": "^1.11.5", "phpunit/phpunit": "^10.5.35|^11.3.6", "predis/predis": "^2.3", @@ -1365,8 +1366,8 @@ "league/flysystem-read-only": "Required to use read-only disks (^3.25.1)", "league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.25.1).", "mockery/mockery": "Required to use mocking (^1.6).", - "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", "pda/pheanstalk": "Required to use the beanstalk queue driver (^5.0).", + "php-http/discovery": "Required to use PSR-7 bridging features (^1.15).", "phpunit/phpunit": "Required to use assertions and run tests (^10.5|^11.0).", "predis/predis": "Required to use the predis connector (^2.3).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", @@ -1387,6 +1388,7 @@ }, "autoload": { "files": [ + "src/Illuminate/Collections/functions.php", "src/Illuminate/Collections/helpers.php", "src/Illuminate/Events/functions.php", "src/Illuminate/Filesystem/functions.php", @@ -1424,7 +1426,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-11-27T15:43:57+00:00" + "time": "2024-12-12T18:25:58+00:00" }, { "name": "laravel/prompts", @@ -1548,16 +1550,16 @@ }, { "name": "league/commonmark", - "version": "2.5.3", + "version": "2.6.0", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "b650144166dfa7703e62a22e493b853b58d874b0" + "reference": "d150f911e0079e90ae3c106734c93137c184f932" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/b650144166dfa7703e62a22e493b853b58d874b0", - "reference": "b650144166dfa7703e62a22e493b853b58d874b0", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/d150f911e0079e90ae3c106734c93137c184f932", + "reference": "d150f911e0079e90ae3c106734c93137c184f932", "shasum": "" }, "require": { @@ -1582,8 +1584,9 @@ "phpstan/phpstan": "^1.8.2", "phpunit/phpunit": "^9.5.21 || ^10.5.9 || ^11.0.0", "scrutinizer/ocular": "^1.8.1", - "symfony/finder": "^5.3 | ^6.0 || ^7.0", - "symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 || ^7.0", + "symfony/finder": "^5.3 | ^6.0 | ^7.0", + "symfony/process": "^5.4 | ^6.0 | ^7.0", + "symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0 | ^7.0", "unleashedtech/php-coding-standard": "^3.1.1", "vimeo/psalm": "^4.24.0 || ^5.0.0" }, @@ -1593,7 +1596,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.6-dev" + "dev-main": "2.7-dev" } }, "autoload": { @@ -1650,7 +1653,7 @@ "type": "tidelift" } ], - "time": "2024-08-16T11:46:16+00:00" + "time": "2024-12-07T15:34:16+00:00" }, { "name": "league/config", @@ -1922,18 +1925,192 @@ ], "time": "2024-09-21T08:32:55+00:00" }, + { + "name": "league/uri", + "version": "7.5.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "81fb5145d2644324614cc532b28efd0215bda430" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/81fb5145d2644324614cc532b28efd0215bda430", + "reference": "81fb5145d2644324614cc532b28efd0215bda430", + "shasum": "" + }, + "require": { + "league/uri-interfaces": "^7.5", + "php": "^8.1" + }, + "conflict": { + "league/uri-schemes": "^1.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-fileinfo": "to create Data URI from file contennts", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "jeremykendall/php-domain-parser": "to resolve Public Suffix and Top Level Domain", + "league/uri-components": "Needed to easily manipulate URI objects components", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "URI manipulation library", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "middleware", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "uri-template", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri/tree/7.5.1" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-12-08T08:40:02+00:00" + }, + { + "name": "league/uri-interfaces", + "version": "7.5.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri-interfaces.git", + "reference": "08cfc6c4f3d811584fb09c37e2849e6a7f9b0742" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/08cfc6c4f3d811584fb09c37e2849e6a7f9b0742", + "reference": "08cfc6c4f3d811584fb09c37e2849e6a7f9b0742", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "php": "^8.1", + "psr/http-factory": "^1", + "psr/http-message": "^1.1 || ^2.0" + }, + "suggest": { + "ext-bcmath": "to improve IPV4 host parsing", + "ext-gmp": "to improve IPV4 host parsing", + "ext-intl": "to handle IDN host with the best performance", + "php-64bit": "to improve IPV4 host parsing", + "symfony/polyfill-intl-idn": "to handle IDN host via the Symfony polyfill if ext-intl is not present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "Common interfaces and classes for URI representation and interaction", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri-src/issues", + "source": "https://github.com/thephpleague/uri-interfaces/tree/7.5.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2024-12-08T08:18:47+00:00" + }, { "name": "livewire/livewire", - "version": "v3.5.16", + "version": "v3.5.17", "source": { "type": "git", "url": "https://github.com/livewire/livewire.git", - "reference": "0b842088d716cadaf9d94fc4f096bc688db29d65" + "reference": "7bbf80d93db9b866776bf957ca6229364bca8d87" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/livewire/zipball/0b842088d716cadaf9d94fc4f096bc688db29d65", - "reference": "0b842088d716cadaf9d94fc4f096bc688db29d65", + "url": "https://api.github.com/repos/livewire/livewire/zipball/7bbf80d93db9b866776bf957ca6229364bca8d87", + "reference": "7bbf80d93db9b866776bf957ca6229364bca8d87", "shasum": "" }, "require": { @@ -1988,7 +2165,7 @@ "description": "A front-end framework for Laravel.", "support": { "issues": "https://github.com/livewire/livewire/issues", - "source": "https://github.com/livewire/livewire/tree/v3.5.16" + "source": "https://github.com/livewire/livewire/tree/v3.5.17" }, "funding": [ { @@ -1996,20 +2173,20 @@ "type": "github" } ], - "time": "2024-12-02T15:57:58+00:00" + "time": "2024-12-06T13:41:21+00:00" }, { "name": "monolog/monolog", - "version": "3.8.0", + "version": "3.8.1", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "32e515fdc02cdafbe4593e30a9350d486b125b67" + "reference": "aef6ee73a77a66e404dd6540934a9ef1b3c855b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/32e515fdc02cdafbe4593e30a9350d486b125b67", - "reference": "32e515fdc02cdafbe4593e30a9350d486b125b67", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/aef6ee73a77a66e404dd6540934a9ef1b3c855b4", + "reference": "aef6ee73a77a66e404dd6540934a9ef1b3c855b4", "shasum": "" }, "require": { @@ -2087,7 +2264,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/3.8.0" + "source": "https://github.com/Seldaek/monolog/tree/3.8.1" }, "funding": [ { @@ -2099,7 +2276,7 @@ "type": "tidelift" } ], - "time": "2024-11-12T13:57:08+00:00" + "time": "2024-12-05T17:15:07+00:00" }, { "name": "nesbot/carbon", @@ -3472,16 +3649,16 @@ }, { "name": "symfony/console", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf" + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", - "reference": "23c8aae6d764e2bae02d2a99f7532a7f6ed619cf", + "url": "https://api.github.com/repos/symfony/console/zipball/fefcc18c0f5d0efe3ab3152f15857298868dc2c3", + "reference": "fefcc18c0f5d0efe3ab3152f15857298868dc2c3", "shasum": "" }, "require": { @@ -3545,7 +3722,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.2.0" + "source": "https://github.com/symfony/console/tree/v7.2.1" }, "funding": [ { @@ -3561,7 +3738,7 @@ "type": "tidelift" } ], - "time": "2024-11-06T14:24:19+00:00" + "time": "2024-12-11T03:49:26+00:00" }, { "name": "symfony/css-selector", @@ -3697,16 +3874,16 @@ }, { "name": "symfony/error-handler", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "672b3dd1ef8b87119b446d67c58c106c43f965fe" + "reference": "6150b89186573046167796fa5f3f76601d5145f8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/672b3dd1ef8b87119b446d67c58c106c43f965fe", - "reference": "672b3dd1ef8b87119b446d67c58c106c43f965fe", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/6150b89186573046167796fa5f3f76601d5145f8", + "reference": "6150b89186573046167796fa5f3f76601d5145f8", "shasum": "" }, "require": { @@ -3752,7 +3929,7 @@ "description": "Provides tools to manage errors and ease debugging PHP code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/error-handler/tree/v7.2.0" + "source": "https://github.com/symfony/error-handler/tree/v7.2.1" }, "funding": [ { @@ -3768,7 +3945,7 @@ "type": "tidelift" } ], - "time": "2024-11-05T15:35:02+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/event-dispatcher", @@ -4136,16 +4313,16 @@ }, { "name": "symfony/http-kernel", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d" + "reference": "d8ae58eecae44c8e66833e76cc50a4ad3c002d97" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d", - "reference": "6b4722a25e0aed1ccb4914b9bcbd493cc4676b4d", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/d8ae58eecae44c8e66833e76cc50a4ad3c002d97", + "reference": "d8ae58eecae44c8e66833e76cc50a4ad3c002d97", "shasum": "" }, "require": { @@ -4230,7 +4407,7 @@ "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/http-kernel/tree/v7.2.0" + "source": "https://github.com/symfony/http-kernel/tree/v7.2.1" }, "funding": [ { @@ -4246,7 +4423,7 @@ "type": "tidelift" } ], - "time": "2024-11-29T08:42:40+00:00" + "time": "2024-12-11T12:09:10+00:00" }, { "name": "symfony/mailer", @@ -4330,16 +4507,16 @@ }, { "name": "symfony/mime", - "version": "v7.2.0", + "version": "v7.2.1", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d" + "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/cc84a4b81f62158c3846ac7ff10f696aae2b524d", - "reference": "cc84a4b81f62158c3846ac7ff10f696aae2b524d", + "url": "https://api.github.com/repos/symfony/mime/zipball/7f9617fcf15cb61be30f8b252695ed5e2bfac283", + "reference": "7f9617fcf15cb61be30f8b252695ed5e2bfac283", "shasum": "" }, "require": { @@ -4394,7 +4571,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v7.2.0" + "source": "https://github.com/symfony/mime/tree/v7.2.1" }, "funding": [ { @@ -4410,7 +4587,7 @@ "type": "tidelift" } ], - "time": "2024-11-23T09:19:39+00:00" + "time": "2024-12-07T08:50:44+00:00" }, { "name": "symfony/polyfill-ctype", @@ -4438,8 +4615,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4514,8 +4691,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4593,8 +4770,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4675,8 +4852,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4759,8 +4936,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4833,8 +5010,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4913,8 +5090,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -4995,8 +5172,8 @@ "type": "library", "extra": { "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" } }, "autoload": { @@ -6118,13 +6295,13 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-master": "3.2-dev" - }, "laravel": { "providers": [ "Barryvdh\\LaravelIdeHelper\\IdeHelperServiceProvider" ] + }, + "branch-alias": { + "dev-master": "3.2-dev" } }, "autoload": { @@ -6376,29 +6553,27 @@ }, { "name": "doctrine/deprecations", - "version": "1.1.3", + "version": "1.1.4", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab" + "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", - "reference": "dfbaa3c2d2e9a9df1118213f3b8b0c597bb99fab", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/31610dbb31faa98e6b5447b62340826f54fbc4e9", + "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9", - "phpstan/phpstan": "1.4.10 || 1.10.15", - "phpstan/phpstan-phpunit": "^1.0", + "doctrine/coding-standard": "^9 || ^12", + "phpstan/phpstan": "1.4.10 || 2.0.3", + "phpstan/phpstan-phpunit": "^1.0 || ^2", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "psalm/plugin-phpunit": "0.18.4", - "psr/log": "^1 || ^2 || ^3", - "vimeo/psalm": "4.30.0 || 5.12.0" + "psr/log": "^1 || ^2 || ^3" }, "suggest": { "psr/log": "Allows logging deprecations via PSR-3 logger implementation" @@ -6406,7 +6581,7 @@ "type": "library", "autoload": { "psr-4": { - "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + "Doctrine\\Deprecations\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -6417,27 +6592,27 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.3" + "source": "https://github.com/doctrine/deprecations/tree/1.1.4" }, - "time": "2024-01-30T19:34:25+00:00" + "time": "2024-12-07T21:18:45+00:00" }, { "name": "driftingly/rector-laravel", - "version": "1.2.5", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/driftingly/rector-laravel.git", - "reference": "82cc1dedb0a4b776102a5e69541232d9ee14706d" + "reference": "7de906ae5772c2993ee6baf683d87c90a850ed96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/82cc1dedb0a4b776102a5e69541232d9ee14706d", - "reference": "82cc1dedb0a4b776102a5e69541232d9ee14706d", + "url": "https://api.github.com/repos/driftingly/rector-laravel/zipball/7de906ae5772c2993ee6baf683d87c90a850ed96", + "reference": "7de906ae5772c2993ee6baf683d87c90a850ed96", "shasum": "" }, "require": { "php": "^7.2 || ^8.0", - "rector/rector": "^1.0" + "rector/rector": "^2.0" }, "type": "rector-extension", "autoload": { @@ -6452,9 +6627,9 @@ "description": "Rector upgrades rules for Laravel Framework", "support": { "issues": "https://github.com/driftingly/rector-laravel/issues", - "source": "https://github.com/driftingly/rector-laravel/tree/1.2.5" + "source": "https://github.com/driftingly/rector-laravel/tree/2.0.0" }, - "time": "2024-11-04T19:26:15+00:00" + "time": "2024-12-12T22:16:05+00:00" }, { "name": "myclabs/deep-copy", @@ -6959,16 +7134,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "11.0.7", + "version": "11.0.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca" + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f7f08030e8811582cc459871d28d6f5a1a4d35ca", - "reference": "f7f08030e8811582cc459871d28d6f5a1a4d35ca", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/418c59fd080954f8c4aa5631d9502ecda2387118", + "reference": "418c59fd080954f8c4aa5631d9502ecda2387118", "shasum": "" }, "require": { @@ -6987,7 +7162,7 @@ "theseer/tokenizer": "^1.2.3" }, "require-dev": { - "phpunit/phpunit": "^11.4.1" + "phpunit/phpunit": "^11.5.0" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -7025,7 +7200,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.7" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/11.0.8" }, "funding": [ { @@ -7033,7 +7208,7 @@ "type": "github" } ], - "time": "2024-10-09T06:21:38+00:00" + "time": "2024-12-11T12:34:27+00:00" }, { "name": "phpunit/php-file-iterator", @@ -7481,23 +7656,23 @@ }, { "name": "sebastian/code-unit", - "version": "3.0.1", + "version": "3.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "6bb7d09d6623567178cf54126afa9c2310114268" + "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/6bb7d09d6623567178cf54126afa9c2310114268", - "reference": "6bb7d09d6623567178cf54126afa9c2310114268", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca", + "reference": "ee88b0cdbe74cf8dd3b54940ff17643c0d6543ca", "shasum": "" }, "require": { "php": ">=8.2" }, "require-dev": { - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.5" }, "type": "library", "extra": { @@ -7526,7 +7701,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/code-unit/issues", "security": "https://github.com/sebastianbergmann/code-unit/security/policy", - "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.1" + "source": "https://github.com/sebastianbergmann/code-unit/tree/3.0.2" }, "funding": [ { @@ -7534,7 +7709,7 @@ "type": "github" } ], - "time": "2024-07-03T04:44:28+00:00" + "time": "2024-12-12T09:59:06+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -7860,16 +8035,16 @@ }, { "name": "sebastian/exporter", - "version": "6.1.3", + "version": "6.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e" + "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", - "reference": "c414673eee9a8f9d51bbf8d61fc9e3ef1e85b20e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/3473f61172093b2da7de1fb5782e1f24cc036dc3", + "reference": "3473f61172093b2da7de1fb5782e1f24cc036dc3", "shasum": "" }, "require": { @@ -7878,7 +8053,7 @@ "sebastian/recursion-context": "^6.0" }, "require-dev": { - "phpunit/phpunit": "^11.2" + "phpunit/phpunit": "^11.3" }, "type": "library", "extra": { @@ -7926,7 +8101,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", "security": "https://github.com/sebastianbergmann/exporter/security/policy", - "source": "https://github.com/sebastianbergmann/exporter/tree/6.1.3" + "source": "https://github.com/sebastianbergmann/exporter/tree/6.3.0" }, "funding": [ { @@ -7934,7 +8109,7 @@ "type": "github" } ], - "time": "2024-07-03T04:56:19+00:00" + "time": "2024-12-05T09:17:50+00:00" }, { "name": "sebastian/global-state", @@ -8347,16 +8522,16 @@ }, { "name": "symplify/easy-coding-standard", - "version": "12.4.0", + "version": "12.5.4", "source": { "type": "git", "url": "https://github.com/easy-coding-standard/easy-coding-standard.git", - "reference": "54d26710fc05c733cbd788a23a709e7815ab0a67" + "reference": "5673ecbc03eef9d7b2f563819c80e8e1ce0161be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/54d26710fc05c733cbd788a23a709e7815ab0a67", - "reference": "54d26710fc05c733cbd788a23a709e7815ab0a67", + "url": "https://api.github.com/repos/easy-coding-standard/easy-coding-standard/zipball/5673ecbc03eef9d7b2f563819c80e8e1ce0161be", + "reference": "5673ecbc03eef9d7b2f563819c80e8e1ce0161be", "shasum": "" }, "require": { @@ -8392,7 +8567,7 @@ ], "support": { "issues": "https://github.com/easy-coding-standard/easy-coding-standard/issues", - "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.4.0" + "source": "https://github.com/easy-coding-standard/easy-coding-standard/tree/12.5.4" }, "funding": [ { @@ -8404,7 +8579,7 @@ "type": "github" } ], - "time": "2024-12-03T12:53:56+00:00" + "time": "2024-12-12T15:36:04+00:00" }, { "name": "theseer/tokenizer", @@ -8458,16 +8633,16 @@ }, { "name": "tomasvotruba/class-leak", - "version": "1.2.6", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/TomasVotruba/class-leak.git", - "reference": "0fa4d5ccfcc1896f887a484a01976596d5d500f1" + "reference": "c3fd35b3de6b92c4b9c5b54a12574c57f1359d4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/TomasVotruba/class-leak/zipball/0fa4d5ccfcc1896f887a484a01976596d5d500f1", - "reference": "0fa4d5ccfcc1896f887a484a01976596d5d500f1", + "url": "https://api.github.com/repos/TomasVotruba/class-leak/zipball/c3fd35b3de6b92c4b9c5b54a12574c57f1359d4a", + "reference": "c3fd35b3de6b92c4b9c5b54a12574c57f1359d4a", "shasum": "" }, "require": { @@ -8490,7 +8665,7 @@ "description": "Detect leaking classes", "support": { "issues": "https://github.com/TomasVotruba/class-leak/issues", - "source": "https://github.com/TomasVotruba/class-leak/tree/1.2.6" + "source": "https://github.com/TomasVotruba/class-leak/tree/2.0.0" }, "funding": [ { @@ -8502,15 +8677,15 @@ "type": "github" } ], - "time": "2024-12-03T17:03:53+00:00" + "time": "2024-12-12T11:53:51+00:00" } ], "aliases": [ { "package": "rector/rector", "version": "dev-main", - "alias": "1.2.9", - "alias_normalized": "1.2.9.0" + "alias": "2.0", + "alias_normalized": "2.0.0.0" } ], "minimum-stability": "stable", diff --git a/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md b/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md index 8503185b9..d8e45749e 100644 --- a/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md +++ b/resources/blog/posts/2024/2024-12-12-5-new-features-in-rector-20.md @@ -2,9 +2,9 @@ id: 74 title: "5 New Features in Rector 2.0" perex: | - Rector 2 is out! We've upgraded to PHPStan 2 and PHP-Parser 5. Based on testing on a couple huge legacy projects, Rector now runs **10-15 %** faster. + Rector 2 is out! We've upgraded to PHPStan 2 and PHP-Parser 5. Based on testing on several huge legacy projects, Rector now runs **10-15 %** faster. - We've also managed to fit in couple new features. + We've also managed to fit in a couple of new features. --- Let's take a look at what's new. @@ -13,7 +13,7 @@ Let's take a look at what's new. ## 1. The `--only` Option to run 1 Rule -At the moment, the Rector repository has a `rector.php` config that enables runs 350+ rules. What if we add a single custom rule and want to run only that one? We'd have to comment out all other rules, run Rector, and then uncomment them back. That's a lot of manual work, right? +At the moment, the Rector repository has a `rector.php` config that enables the running of 350+ rules. What if we add a single custom rule and want to run only that one? We'd have to comment out all other rules, run Rector, and then uncomment them back. That's a lot of manual work, right?
@@ -23,15 +23,13 @@ At the moment, the Rector repository has a `rector.php` config that enables runs vendor/bin/rector process src --only="Utils\Rector\MoveTraitsToConstructorRector" ``` -It's was a tough challenge to make all quotes and slashes in CLI work across all operating systems. - -Thanks to [Christian Weiske](https://github.com/rectorphp/rector-src/pull/6441) who's done a great job on this feature. +Making all quotes and slashes in CLI work across all operating systems was a tough challenge. Thanks to [Christian Weiske](https://github.com/rectorphp/rector-src/pull/6441), who's done a great job on this feature.
## 2. Introducing Composer-based sets -In the wild, the vendor-sets like Symfony, Twig, Laravel or Doctrine, have many sets - each containing a group or rules for specific version. Symfony has over 20 sets, but let's look at simpler example - Twig: +In the wild, vendor sets like Symfony, Twig, Laravel, or Doctrine have many sets - each containing a group or rules for a specific version. Symfony has over 20 sets, but let's look at a more straightforward example - Twig: ```php use Rector\Config\RectorConfig; @@ -48,7 +46,7 @@ return RectorConfig::configure()
-This is wrong for many reasons. It can lead to: +This doesn't seem right for many reasons. It can lead to: * bloated `rector.php` file * missed new set, as we have to always add new sets as they're published @@ -56,16 +54,16 @@ This is wrong for many reasons. It can lead to:
-Instead, **Rector should be able to pick up version from installed version, and provide only relevant rules**. +Instead, **the Rector should be able to pick up the version from the installed version and provide only relevant rules**. -Fully automated, like following: +Fully automated, like the following: ```php return RectorConfig::configure() ->withComposerBased(twig: true) ``` -Currently we provide `twig`, `doctrine` and `phpunit` composer-based sets. +Currently, we provide `twig`, `doctrine`, and `phpunit` composer-based sets. If you want to **know how it works behind the scenes**, check [this dedicated post](/blog/introducing-composer-version-based-sets). @@ -91,7 +89,7 @@ It works for all `->withPhp*Sets()` too. ## 4. Smarter Annotations to Attributes sets -We're proving [annotations to attributes upgrade](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes) since PHP 8.0 day one. You can enable them in `rector.php` easily: +We've been providing [annotations to attributes upgrade](https://getrector.com/blog/how-to-upgrade-annotations-to-attributes) since PHP 8.0 day. You can enable them in `rector.php` easily: ```php use Rector\Config\RectorConfig; @@ -102,7 +100,7 @@ return RectorConfig::configure()
-In reality, some packages add attribute support a bit later. E.g. Rector 2 ships with [Behat attributes](https://github.com/rectorphp/rector-src/pull/6510) contributed by [Carlos Granados](https://github.com/carlos-granados). To use them in our project, we'd have to change the config: +In reality, some packages add attribute support a bit later. E.g., Rector 2 ships with [Behat attributes](https://github.com/rectorphp/rector-src/pull/6510) contributed by [Carlos Granados](https://github.com/carlos-granados). To use them in our project, we'd have to change the config: ```diff use Rector\Config\RectorConfig; @@ -114,7 +112,7 @@ In reality, some packages add attribute support a bit later. E.g. Rector 2 ships
-But who has time to keep checking if this or that package has new attribute sets. Instead, **make the method empty**: +But who has time to check if this or that package has new attribute sets? Instead, **make the method empty**: ```diff use Rector\Config\RectorConfig; @@ -124,7 +122,7 @@ But who has time to keep checking if this or that package has new attribute sets + ->withAttributesSets(); ``` -Now Rector will pick up all attribute sets automatically. +Now, the Rector will pick up all attribute sets automatically.
@@ -135,16 +133,18 @@ Also, Rector will now check if the attribute **actually exists before it adds it ## 5. Leaner Custom Rules -Last but not least, we've collected feedback from custom rule creators. We also create many custom rules for our clients. Some of them are temporary, other are fixing simple elements. Still, we always have to fill `getRuleDefinition()` with dummy data, to make Rector happy. In reality, this method is used only by Rector core rules for [Find rule](https://getrector.com/find-rule) page. +Last but not least, we've collected feedback from custom rule creators. We also create many custom rules for our clients. Some of them are temporary, and others fix simple elements. Still, we always have to fill `getRuleDefinition()` with dummy data to make Rector happy. + +In reality, this method is used only by Rector core rules for the [Find rule](https://getrector.com/find-rule) page. -Saying that, we no longer need to write tedious `getRuleDefinition()`. These methods can be finally dropped: +Saying that we no longer need to write tedious `getRuleDefinition()`. Now you can finally drop this method: ```diff use Rector\Rector\AbstractRector; -use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; -use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; - final class SimpleRector extends AbstractRector + Final class SimpleRector extends AbstractRector { - public function getRuleDefinition(): RuleDefinition - { @@ -163,4 +163,3 @@ See the [upgrade guide](https://github.com/rectorphp/rector/blob/main/UPGRADING.
Happy coding! - diff --git a/src/Controller/Stats/FindRuleStatsController.php b/src/Controller/Stats/FindRuleStatsController.php index 27c9ead5e..4df6b6c1c 100644 --- a/src/Controller/Stats/FindRuleStatsController.php +++ b/src/Controller/Stats/FindRuleStatsController.php @@ -56,7 +56,7 @@ public function __invoke(): View */ private function getArrayFlattenKey(array $items, string $keyName): array { - $items = array_map(fn(array $item) => $item[$keyName], $items); + $items = array_map(fn (array $item) => $item[$keyName], $items); // remove empty ones return array_filter($items); diff --git a/src/FileSystem/RectorFinder.php b/src/FileSystem/RectorFinder.php index 45dd6fcb3..f2cb01311 100644 --- a/src/FileSystem/RectorFinder.php +++ b/src/FileSystem/RectorFinder.php @@ -76,6 +76,11 @@ public function findBySlug(string $slug): ?RuleMetadata return null; } + public function getRuleCount(): int + { + return count($this->findCore()) + count($this->findCommunity()); + } + /** * @param string[] $directories * @return array> @@ -166,9 +171,4 @@ private function findInDirectoriesAndCreateRuleMetadatas(array $directories, arr return $ruleMetadatas; } - - public function getRuleCount(): int - { - return count($this->findCore()) + count($this->findCommunity()); - } } diff --git a/src/Providers/AppServiceProvider.php b/src/Providers/AppServiceProvider.php index 99c75ea89..fb19ecb37 100644 --- a/src/Providers/AppServiceProvider.php +++ b/src/Providers/AppServiceProvider.php @@ -21,7 +21,10 @@ public function register(): void { $this->app->singleton(RectorSetsTreeProvider::class); - $this->app->singleton(SymfonyStyle::class, fn(): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput())); + $this->app->singleton( + SymfonyStyle::class, + fn (): SymfonyStyle => new SymfonyStyle(new ArrayInput([]), new ConsoleOutput()) + ); $this->app->singleton(MarkdownDiffer::class, function (): MarkdownDiffer { // this is required to show full diffs from start to end diff --git a/src/RuleFilter/ConfiguredDiffSamplesFactory.php b/src/RuleFilter/ConfiguredDiffSamplesFactory.php index 02faf41cf..bee7e9a74 100644 --- a/src/RuleFilter/ConfiguredDiffSamplesFactory.php +++ b/src/RuleFilter/ConfiguredDiffSamplesFactory.php @@ -63,12 +63,12 @@ private function resolveConfiguredCodeSampleNews(array $stmts): array $nodeFinder = new NodeFinder(); /** @var New_[] $configuredCodeSampleNews */ - $configuredCodeSampleNews = $nodeFinder->find($stmts, fn(Node $node): bool => + $configuredCodeSampleNews = $nodeFinder->find($stmts, fn (Node $node): bool => // we look for "new ConfiguredCodeSample()" $this->isNewWithClassName( - $node, - 'Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample' - )); + $node, + 'Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample' + )); return $configuredCodeSampleNews; } diff --git a/src/RuleFilter/RuleFilter.php b/src/RuleFilter/RuleFilter.php index 56c03886e..1ca8465b2 100644 --- a/src/RuleFilter/RuleFilter.php +++ b/src/RuleFilter/RuleFilter.php @@ -65,7 +65,7 @@ private function filterByQuery(array $ruleMetadatas, ?string $query): array // sort by score usort( $filteredRuleMetadatas, - fn(RuleMetadata $firstRuleMetadata, RuleMetadata $secondRuleMetadata): int => $secondRuleMetadata->getFilterScore() <=> $firstRuleMetadata->getFilterScore() + fn (RuleMetadata $firstRuleMetadata, RuleMetadata $secondRuleMetadata): int => $secondRuleMetadata->getFilterScore() <=> $firstRuleMetadata->getFilterScore() ); return $filteredRuleMetadatas; diff --git a/src/Utils/Arrays.php b/src/Utils/Arrays.php index c20ff6085..d2e57191f 100644 --- a/src/Utils/Arrays.php +++ b/src/Utils/Arrays.php @@ -16,6 +16,6 @@ public static function groupToCount(array $items, int $requiredCount = 1): array arsort($itemsToValues); // at least twice - return array_filter($itemsToValues, fn(int $count): bool => $count > $requiredCount); + return array_filter($itemsToValues, fn (int $count): bool => $count > $requiredCount); } }