Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions config/set/php-polyfills.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php73\Rector\BooleanOr\IsCountableRector;
use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector;
use Rector\Php80\Rector\Identical\StrEndsWithRector;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\Php80\Rector\NotIdentical\StrContainsRector;
use Rector\Php80\Rector\Ternary\GetDebugTypeRector;

// these rules can be used ahead of PHP version,
// as long composer.json includes particular symfony/php-polyfill package
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
ArrayKeyFirstLastRector::class,
IsCountableRector::class,
GetDebugTypeRector::class,
StrStartsWithRector::class,
StrEndsWithRector::class,
StrContainsRector::class,
]);
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone notices this set should be more complete, let us know 😉

3 changes: 3 additions & 0 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ public function withPhpSets(
$this->sets[] = LevelSetList::UP_TO_PHP_84;
}

// make use of polyfill packages in composer.json
$this->sets[] = SetList::PHP_POLYFILLS;
Comment on lines +460 to +461

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be enabled manually via passed config, for example, we use withPhpSets(php53: true), it doesn't make sense to have str_starts_with() change? That will make too much change when it on step by step migration.

I think user needs to enable it by, eg: withPhpSets(php53: true, polyfill: true)

wdyt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think add new method: withPhpPolyfill() can be the way to go

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, thanks 👍


return $this;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Set/ValueObject/SetList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
*/
final class SetList implements SetListInterface
{
/**
* @var string
*/
public const PHP_POLYFILLS = __DIR__ . '/../../../config/set/php-polyfills.php';

/**
* @var string
*/
Expand Down