Skip to content

Commit

Permalink
Add missing tests and update documentation (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo authored Aug 19, 2024
1 parent de7f93b commit 1bdaead
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 17 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Rector Rules for Contao Open Source CMS

This project contains [Rector rules](https://github.com/rectorphp/rector) for [Contao Open Source CMS](https://contao/contao) upgrades.
This project contains [Rector rules](https://github.com/rectorphp/rector)
for [Contao Open Source CMS](https://contao/contao) upgrades.

**!! WARNING !! this is currently experimental, use at your own risk**

Expand All @@ -14,21 +15,13 @@ composer require contao/contao-rector --dev

## Available sets

**ContaoSetList::CONTAO_49**
updates your code to compatibility with Contao 4.9

**ContaoSetList::CONTAO_413**
updates your code to compatibility with Contao 4.13

**ContaoSetList::CONTAO_50**
updates your code to compatibility with Contao 5.0

**ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES**
converts Contao annotations (e.g. `@Hook("...")`) to attributes (e.g. `#[AsHook('...')]`)

**ContaoSetList::FQCN**
upgrades class namespaces from global (e.g. `\StringUtil`) to Contao (e.g. `\Contao\StringUtil`)

| Sets | Description |
|:-----------------------------------------------|:-------------------------------------------------------------------------------------------------|
| ```ContaoSetList::CONTAO_49``` | updates your code to compatibility with Contao 4.9 |
| ```ContaoSetList::CONTAO_413``` | updates your code to compatibility with Contao 4.13 |
| ```ContaoSetList::CONTAO_50``` | updates your code to compatibility with Contao 5.0 |
| ```ContaoSetList::ANNOTATIONS_TO_ATTRIBUTES``` | converts Contao annotations (e.g. `@Hook("...")`) to attributes (e.g. `#[AsHook('...')]`) |
| ```ContaoSetList::FQCN``` | upgrades class namespaces from global (e.g. `\StringUtil`) to Contao (e.g. `\Contao\StringUtil`) |

## Available level sets

Expand All @@ -41,3 +34,11 @@ to PHP 7.4 and Symfony 5.4, since Contao 4.13 does not support any lower version
## Available rules

* [Explore the current Rector rules](/docs/rules_overview.md)

### Development

You can generate the rules with the following command:

```shell
vendor/bin/rule-doc-generator generate src/Rector --output-file docs/rules_overview.md
```
15 changes: 14 additions & 1 deletion docs/rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 12 Rules Overview
# 13 Rules Overview

## ConstantToClassConstantRector

Expand Down Expand Up @@ -45,6 +45,19 @@ Fixes deprecated constants to service parameters

<br>

## ContainerSessionToRequestStackSessionRector

Rewrites session access to the request stack session

- class: [`Contao\Rector\Rector\ContainerSessionToRequestStackSessionRector`](../src/Rector/ContainerSessionToRequestStackSessionRector.php)

```diff
-\Contao\System::getContainer()->get('session');
+\Contao\System::getContainer()->get('request_stack')->getSession();
```

<br>

## ControllerMethodToVersionsClassRector

Fixes deprecated `Controller::createInitialVersion()` and `Controller::createNewVersion()` to Versions class calls
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Contao\Rector\Tests\Rector\ContainerSessionToRequestStackSessionRector;

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

final class ContainerSessionToRequestStackSessionRectorTest 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/config.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Contao\Rector\Rector\ContainerSessionToRequestStackSessionRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(ContainerSessionToRequestStackSessionRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo extends Controller
{
public function bar()
{
$session = \Contao\System::getContainer()->get('session');
}
}
?>
-----
<?php

class Foo extends Controller
{
public function bar()
{
$session = \Contao\System::getContainer()->get('request_stack')->getSession();
}
}
?>

0 comments on commit 1bdaead

Please sign in to comment.