Skip to content

Commit

Permalink
Merge pull request #234 from Kharhamel/rectorFix
Browse files Browse the repository at this point in the history
Fixed the rector bug
  • Loading branch information
Kharhamel committed Sep 3, 2020
2 parents aa7aae7 + 3266d6b commit 0094669
Show file tree
Hide file tree
Showing 8 changed files with 1,187 additions and 1,134 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/auto-regenerate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ jobs:
run: "composer install --no-interaction"
working-directory: "generator"

- name: "Install dependencies with composer in root directory"
run: "composer install --no-interaction"


- name: "Dump autoloader with composer in root directory"
run: "composer dump-autoload"


- name: "Regenerate files"
run: "./safe.php generate"
working-directory: "generator"
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ jobs:
exit 1;
fi
- name: "Check if refactoring can be done with rector/rector:~0.7.0"
run: "composer install && composer rector && composer test"
working-directory: "generator/tests/rector/0.7"

- name: "Archive code coverage results"
uses: "actions/upload-artifact@v1"
with:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/rector-continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions

name: "Rector Continuous Integration"

on:
- "pull_request"
- "push"

jobs:

rector-continuous-integration:
name: "Check if refactoring can be done with rector/rector:~0.7.0"

runs-on: "ubuntu-latest"

strategy:
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"

dependencies:
- "highest"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: "Composer install"
run: "composer install && composer rector && composer test"
working-directory: "generator/tests/rector/0.7"

- name: "Run rector"
run: "composer rector"
working-directory: "generator/tests/rector/0.7"

- name: "Run tests"
run: "composer test"
working-directory: "generator/tests/rector/0.7"

17 changes: 13 additions & 4 deletions generator/src/FileCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,29 @@ public function generateRectorFileForZeroPointSeven(array $functions, string $pa
}

$header = <<<'TXT'
<?php
declare(strict_types=1);
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
# This file configures rector/rector:~0.7.0 to replace all PHP functions with their equivalent "safe" functions
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
services:
Rector\Renaming\Rector\Function_\RenameFunctionRector:
$oldFunctionToNewFunction:
$services->set(RenameFunctionRector::class)
->call('configure', [[ RenameFunctionRector::OLD_FUNCTION_TO_NEW_FUNCTION => [
TXT;

fwrite($stream, $header);

foreach ($functionNames as $functionName) {
fwrite($stream, ' '.$functionName.": 'Safe\\".$functionName."'\n");
fwrite($stream, " '$functionName' => 'Safe\\$functionName',\n");
}

fwrite($stream, "]]]);\n};\n");
fclose($stream);
}

Expand Down
2 changes: 1 addition & 1 deletion generator/src/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fileCreator = new FileCreator();
$fileCreator->generatePhpFile($functions, __DIR__ . '/../../generated/');
$fileCreator->generateFunctionsList($functions, __DIR__ . '/../../generated/functionsList.php');
$fileCreator->generateRectorFileForZeroPointSeven($functions, __DIR__ . '/../../rector-migrate-0.7.yml');
$fileCreator->generateRectorFileForZeroPointSeven($functions, __DIR__ . '/../../rector-migrate-0.7.php');


$modules = [];
Expand Down
2 changes: 1 addition & 1 deletion generator/tests/rector/0.7/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"phpunit/phpunit": "^7"
},
"scripts": {
"rector": "rector process src/ --config ../../../../rector-migrate-0.7.yml",
"rector": "rector process src/ --config ../../../../rector-migrate-0.7.php",
"test": "phpunit"
}
}

0 comments on commit 0094669

Please sign in to comment.