Skip to content

Commit 9acc5ae

Browse files
authored
Merge pull request #176 from localheinz/feature/rector
Enhancement: Add support for rector/rector:~0.6.0
2 parents fde60a3 + 66c9cc2 commit 9acc5ae

File tree

10 files changed

+1211
-6
lines changed

10 files changed

+1211
-6
lines changed

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/generator/doc/doc-en/
44
/generator/doc/entities/generated.ent
55
/composer.lock
6-
/vendor/
7-
/generator/tests/rector/0.4/composer.lock
8-
/generator/tests/rector/0.4/vendor/
6+
vendor/
7+
/generator/tests/rector/0.5/composer.lock
8+
/generator/tests/rector/0.6/composer.lock

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ script:
6262
exit 1;
6363
fi
6464
- cd generator/tests/rector/0.5 && composer install && composer rector && composer test && cd ../../../..
65+
- cd generator/tests/rector/0.6 && composer install && composer rector && composer test && cd ../../../..
6566

6667
after_script:
6768
- cd generator && travis_retry php vendor/bin/php-coveralls -v --root_dir="./generator"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ tool that performs instant refactoring of your application.
114114
First, you need to install Rector:
115115
116116
```bash
117-
$ composer require --dev rector/rector ^0.5
117+
$ composer require --dev rector/rector ^0.6
118118
```
119119

120120
Now, you simply need to run Rector with this command:
121121

122122
```bash
123-
vendor/bin/rector process src/ --config vendor/thecodingmachine/safe/rector-migrate.yml
123+
vendor/bin/rector process src/ --config vendor/thecodingmachine/safe/rector-migrate-0.6.yml
124124
```
125125

126126
*Note:* do not forget to replace "src/" with the path to your source directory.

generator/src/FileCreator.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function generateFunctionsList(array $functions, string $path): void
116116
}
117117

118118
/**
119+
* @deprecated Official support for rector/rector:~0.5 is not advertised anymore.
120+
*
119121
* This function generate a rector yml file containing a replacer for all functions
120122
*
121123
* @param Method[] $functions
@@ -140,6 +142,39 @@ public function generateRectorFile(array $functions, string $path): void
140142
fclose($stream);
141143
}
142144

145+
/**
146+
* Generates a configuration file for replacing all functions when using rector/rector:~0.6.
147+
*
148+
* @param Method[] $functions
149+
* @param string $path
150+
*/
151+
public function generateRectorFileForZeroPointSix(array $functions, string $path): void
152+
{
153+
$functionNames = $this->getFunctionsNameList($functions);
154+
155+
$stream = fopen($path, 'w');
156+
157+
if ($stream === false) {
158+
throw new \RuntimeException('Unable to write to '.$path);
159+
}
160+
161+
$header = <<<'TXT'
162+
# This file configures rector/rector:~0.6.0 to replace all PHP functions with their equivalent "safe" functions
163+
164+
services:
165+
Rector\Renaming\Rector\Function_\RenameFunctionRector:
166+
$oldFunctionToNewFunction:
167+
168+
TXT;
169+
170+
fwrite($stream, $header);
171+
172+
foreach ($functionNames as $functionName) {
173+
fwrite($stream, ' '.$functionName.": 'Safe\\".$functionName."'\n");
174+
}
175+
176+
fclose($stream);
177+
}
143178

144179
public function createExceptionFile(string $moduleName): void
145180
{

generator/src/GenerateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3838
$fileCreator->generatePhpFile($functions, __DIR__ . '/../../generated/');
3939
$fileCreator->generateFunctionsList($functions, __DIR__ . '/../../generated/functionsList.php');
4040
$fileCreator->generateRectorFile($functions, __DIR__ . '/../../rector-migrate.yml');
41+
$fileCreator->generateRectorFileForZeroPointSix($functions, __DIR__ . '/../../rector-migrate-0.6.yml');
4142

4243

4344
$modules = [];
@@ -75,7 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7576
// Finally, let's edit the composer.json file
7677
$output->writeln('Editing composer.json');
7778
ComposerJsonEditor::editFiles(\array_values($modules));
78-
79+
7980
return 0;
8081
}
8182

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"autoload": {
3+
"psr-4": {
4+
"Test\\": "src/"
5+
}
6+
},
7+
"require": {
8+
"php": "^7.2",
9+
"rector/rector": "^0.6.7"
10+
},
11+
"require-dev": {
12+
"phpunit/phpunit": "^7"
13+
},
14+
"scripts": {
15+
"rector": "rector process src/ --config ../../../../rector-migrate-0.6.yml",
16+
"test": "phpunit"
17+
}
18+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
6+
backupGlobals="false"
7+
backupStaticAttributes="false"
8+
bootstrap="vendor/autoload.php"
9+
colors="true"
10+
convertErrorsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertWarningsToExceptions="true"
13+
processIsolation="false"
14+
stopOnFailure="false"
15+
>
16+
<testsuites>
17+
<testsuite name="Main test Suite">
18+
<directory>./tests/</directory>
19+
</testsuite>
20+
</testsuites>
21+
</phpunit>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
glob('*');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
5+
final class RectorTest extends TestCase
6+
{
7+
public function testRectorSucceeded()
8+
{
9+
$content = file_get_contents(__DIR__.'/../src/test.php');
10+
11+
$this->assertContains('Safe', $content);
12+
}
13+
}

0 commit comments

Comments
 (0)