Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop ComposerTriggeredSet and Custom Set Provider #3

Closed
ghostwriter opened this issue Dec 9, 2024 · 0 comments
Closed

Drop ComposerTriggeredSet and Custom Set Provider #3

ghostwriter opened this issue Dec 9, 2024 · 0 comments

Comments

@ghostwriter
Copy link
Owner

Following up on: rectorphp/rector#8720 (comment) & rectorphp/rector-src#6515

Requiring a pull request to enable every custom SetProvider feels like an unnecessary hurdle for developers who want to extend functionality.

Given current priorities, these feature (ComposerTriggeredSet and Custom Set Provider) will not be pursued further.


Solution:

  • Revert the configuration back to the old syntax and use the RectorConfig::import() method for importing configurations
  • use Composer\InstalledVersions and Composer\Semver\VersionParser for filtering
// `config/phpunit/phpunit/phpunit-11.php`
<?php

declare (strict_types=1);

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig) : void {

    if (! InstalledVersions::satisfies(new VersionParser, 'phpunit/phpunit', '^11.0') ) {
        return;
    }
   
    // rules and sets that are imported;
    // - if the installed version of "phpunit/phpunit" satisfies "^11.0" constraint.

    $rectorConfig->import(__DIR__ . '/phpunit-10.php');
};
  • Implement dynamic config imports.
// `config/revamp.php`
$phpFiles = [];

// Create a RecursiveDirectoryIterator to iterate through the directory
$iterator = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator(__DIR__),
    RecursiveIteratorIterator::LEAVES_ONLY // Only files, not directories
);

// Loop through the files
foreach ($iterator as $file) {
    if (! $file->isFile()) {
        continue; // Skip directories
    }

    $realPath = $file->getRealPath();
    if (! is_string($realPath)) {
        continue; // Skip files that cannot be read
    }

    if(!str_ends_with($realPath, '.php') ) {
        continue; // Skip files that are not PHP files
    }

    $phpFiles[$realPath] = true; // Add the file's full path to the result array
}

unset($phpFiles[__FILE__]); // Remove this file from the array

return RectorConfig::configure()->withSets(array_keys($phpFiles));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant