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
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ This guide is meant for adding rules to this package. For custom project rules,
- `./src/contracts/Sets/ibexa-50.php` is a ruleset which contains all the rules for Ibexa DXP 5.0 upgrade, new rules
should be added there.
* `./src/lib/Rule` - directory to implement specific rules, following [Rector's official doc](https://getrector.com/documentation/custom-rule).
- `./src/lib/Rule/Ibexa50/` - directory to implement Ibexa 5.0 upgrade specific rules
* `./tests/lib/Rule` - directory to implement a specific rule tests, should contain subdirectory named `<RuleName>/`
- `./src/lib/Rule/Ibexa50/` - directory to implement Ibexa 5.0 upgrade specific rules.
* `./tests/lib/Rule` - directory to implement a specific rule tests, should contain subdirectory named `<RuleName>/`.
* `./tests/lib/Sets/Ibexa50/` - directory to implement specific use cases for Ibexa 5.0 set configuration, if not covered by Rector tests.

## Creating custom rules

Expand Down
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,26 @@ composer require --dev ibexa/rector:~5.0.x-dev
## Usage

1. Create `./rector.php` file in your project, with the following contents, adjusted to your project structure:
```php
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src', // see if it matches your project structure
__DIR__ . '/tests',
]);

// define sets of rules
$rectorConfig->sets([
__DIR__ . '/vendor/ibexa/rector/src/contracts/Sets/ibexa-50.php' // rule set for upgrading to Ibexa DXP 5.0
]);
};
```
```php
declare(strict_types=1);

use Ibexa\Contracts\Rector\Sets\IbexaSetList;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths(
[
__DIR__ . '/src', // see if it matches your project structure
__DIR__ . '/tests'
]
)
->withSets(
[
IbexaSetList::IBEXA_50->value // rule set for upgrading to Ibexa DXP 5.0
]
)
;
```
2. Execute Rector
```
php ./bin/rector process <directory>
Expand Down
14 changes: 14 additions & 0 deletions src/contracts/Sets/IbexaSetList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Contracts\Rector\Sets;

enum IbexaSetList: string
{
case IBEXA_50 = __DIR__ . '/ibexa-50.php';
}
7 changes: 7 additions & 0 deletions src/contracts/Sets/ibexa-50.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\Rector\PropertyFetch\RenamePropertyRector;
use Rector\Renaming\ValueObject\RenameClassConstFetch;
use Rector\Renaming\ValueObject\RenameProperty;

return static function (RectorConfig $rectorConfig): void {
// List of rector rules to upgrade Ibexa projects to Ibexa DXP 5.0
$rectorConfig->ruleWithConfiguration(
RenameClassRector::class,
[
'Ibexa\\Bundle\\Core\\ApiLoader\\RepositoryConfigurationProvider' => 'Ibexa\\Contracts\\Core\\Container\\ApiLoader\\RepositoryConfigurationProviderInterface',
]
);

$rectorConfig->ruleWithConfiguration(
RenameClassConstFetchRector::class,
Expand Down
39 changes: 39 additions & 0 deletions tests/lib/Sets/Ibexa50/Fixture/some_class.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Ibexa\Rector\Tests\Sets\Ibexa50\Fixture;

use Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider;

class FooBar {
public function foo(): RepositoryConfigurationProvider
{
return $this->bar(RepositoryConfigurationProvider::class);
}

public function bar(string $class): RepositoryConfigurationProvider
{
return new $class();
}
}

?>
-----
<?php

namespace Ibexa\Rector\Tests\Sets\Ibexa50\Fixture;

use Ibexa\Bundle\Core\ApiLoader\RepositoryConfigurationProvider;

class FooBar {
public function foo(): \Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface
{
return $this->bar(\Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface::class);
Comment on lines +25 to +30
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Rector per design expects that a Developer runs CS fixer afterwards. For the automated PR I'll run CS fixer with extra FQCN import rule, which will both remove unused use and simplify FQCN.

}

public function bar(string $class): \Ibexa\Contracts\Core\Container\ApiLoader\RepositoryConfigurationProviderInterface
{
return new $class();
}
}

?>
31 changes: 31 additions & 0 deletions tests/lib/Sets/Ibexa50/Ibexa50Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rector\Tests\Sets\Ibexa50;

use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class Ibexa50Test extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): \Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
14 changes: 14 additions & 0 deletions tests/lib/Sets/Ibexa50/config/configured_rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

use Ibexa\Contracts\Rector\Sets\IbexaSetList;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([IbexaSetList::IBEXA_50->value]);
};