rector icon indicating copy to clipboard operation
rector copied to clipboard

Feature Request: Add `withSetProviders` method for Registering `SetProviderInterface`

Open ghostwriter opened this issue 1 year ago • 4 comments

Hi,

SetListInterface was deprecated.

/**
 * @deprecated This interface needs a reflection to load and uses constant links. 
 * Now we changed to services provider architecture that can be used and registerd easily. 
 * Use @see SetProviderInterface instead
 */
interface SetListInterface
{
}
// src/Set/Contract/SetListInterface.php
interface SetProviderInterface
{
    /**
     * @return SetInterface[]
     */
    public function provide(): array;
}
// src/Set/Contract/SetProviderInterface.php

Question

Can you please provide documentation or examples on how to register a class that implements the SetProviderInterface using RectorConfigBuilder or RectorConfig.

It is unclear how to properly implement and register the new interface.

Thank you.

ghostwriter avatar Jul 05 '24 13:07 ghostwriter

Hi, this feature is internal. We don't use for public yet. How do you use the deprecated interface?

TomasVotruba avatar Jul 05 '24 16:07 TomasVotruba

SetListInterface is implemented on a few SetList ValueObjects, similar to rector

Before deprecation:

  • https://github.com/ghostwriter/mockery-rector/blob/641386f58fac1504f782745080f69e69de19a26b/src/MockerySetList.php
  • https://github.com/ghostwriter/mockery-rector/blob/641386f58fac1504f782745080f69e69de19a26b/src/MockeryLevelSetList.php

After deprecation:

https://github.com/ghostwriter/mockery-rector/blob/28d60268ff72943df51c561f556d6eb5c412bcfc/src/MockerySetProvider.php

https://github.com/ghostwriter/mockery-rector/blob/28d60268ff72943df51c561f556d6eb5c412bcfc/src/MockerySetList.php

Config:

use Ghostwriter\MockeryRector\MockeryLevelSetList;
use Ghostwriter\MockeryRector\MockerySetList;
use Ghostwriter\MockeryRector\Rule\ExtendMockeryTestCaseRector;
use Ghostwriter\MockeryRector\Rule\HamcrestToPHPUnitRector;
use Ghostwriter\MockeryRector\Rule\PHPUnitToMockeryRector;
use Ghostwriter\MockeryRector\Rule\ProphecyToMockeryRector;
use Ghostwriter\MockeryRector\Rule\ShouldReceiveToAllowsRector;
use Ghostwriter\MockeryRector\Rule\ShouldReceiveToExpectsRector;
use Ghostwriter\MockeryRector\Rule\UseMockeryPHPUnitIntegrationTraitRector;

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withRules([
        // ExtendMockeryTestCaseRector::class,
        // HamcrestToPHPUnitRector::class,
        // PHPUnitToMockeryRector::class,
        // ProphecyToMockeryRector::class,
        // ShouldReceiveToAllowsRector::class,
        // ShouldReceiveToExpectsRector::class,
        // UseMockeryPHPUnitIntegrationTraitRector::class,
    ])
    ->withSets([
         // version sets
         MockerySetList::MOCKERY_1_6, // v1.6.0
         MockerySetList::MOCKERY_2_0, // v2.0.0
         // or level sets
         MockeryLevelSetList::UP_TO_MOCKERY_1_6, // v0.1.0 - v1.6.0
         MockeryLevelSetList::UP_TO_MOCKERY_2_0, // v0.1.0 - v2.0.0
         // or migration sets
         MockerySetList::PHPUNIT_TO_MOCKERY, // PHPUnit to Mockery
         MockerySetList::PROPHECY_TO_MOCKERY, // Prophecy to Mockery
    ]);

ghostwriter avatar Jul 06 '24 03:07 ghostwriter

I would like to use the ComposerTriggeredSet feature.

I would like to see a withSetProviders(string ...$setProviders) method that accepts FQCN (string) of a class that implements SetProviderInterface which we can check via is_a($setProvider, SetProviderInterface::class, true).

return RectorConfig::configure()
    ->withSetProviders(
        PHPSetProvider::class,
        PHPUnitSetProvider::class,
        MockerySetProvider::class,
    );

ghostwriter avatar Jul 06 '24 16:07 ghostwriter

Hi @TomasVotruba,

With the introduction of Composer-Based Sets and Custom Set Providers, Currently, requiring a PR for every custom SetProvider developers create feels like an unnecessary hurdle.

If your parameter is missing, send us a PR to enable it.

It would be great to simplify this step for broader usability with the requested method (or a similar one).

ghostwriter avatar Nov 26 '24 21:11 ghostwriter