Skip to content

Commit

Permalink
Transform sources with Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 16, 2021
1 parent fde7a7a commit 571c56d
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 133 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compiler-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
php-version: "8.0"

- name: "Install dependencies"
run: "composer install --no-dev --no-interaction --no-progress"
run: "composer install --no-interaction --no-progress"

- name: "Transform source code"
run: php bin/transform-source.php
run: build/transform-source

- name: "Tests"
run: |
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,23 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: 8.0

- name: "Transform source code"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
run: php bin/transform-source.php
run: build/transform-source

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"

- name: "Lint"
run: "make lint"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phar-old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
run: "composer install --no-interaction --no-progress --working-dir=compiler"

- name: "Transform source code"
run: php bin/transform-source.php
run: build/transform-source

- name: "Compile PHAR"
run: php compiler/bin/compile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: "composer install --no-interaction --no-progress --working-dir=compiler"

- name: "Transform source code"
run: php bin/transform-source.php
run: build/transform-source

- name: "Compile PHAR"
run: php compiler/bin/compile
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,26 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: 8.0
extensions: mbstring

- name: "Transform source code"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
run: php bin/transform-source.php
shell: bash
run: build/transform-source

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
extensions: mbstring

- name: "Downgrade PHPUnit"
if: matrix.php-version == '7.1' || matrix.php-version == '7.2'
Expand Down
39 changes: 37 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,28 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: 8.0
extensions: mbstring

- name: "Transform source code"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
run: php bin/transform-source.php
shell: bash
run: build/transform-source

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '7.4' && matrix.php-version != '8.0' && matrix.php-version != '8.1'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-values: memory_limit=640M

- name: "Tests"
run: "${{ matrix.script }}"
Expand Down Expand Up @@ -87,8 +106,24 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.0"

- name: "Transform source code"
run: php bin/transform-source.php
shell: bash
run: build/transform-source

- name: "Reinstall matrix PHP version"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: pecl
extensions: ds,mbstring
ini-values: memory_limit=640M

- name: "Downgrade PHPUnit"
run: "composer require --dev phpunit/phpunit:^7.5.20 brianium/paratest:^4.0 --update-with-dependencies"
Expand Down
122 changes: 0 additions & 122 deletions bin/transform-source.php

This file was deleted.

18 changes: 18 additions & 0 deletions build/rector-downgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();

$parameters->set(Option::SKIP, [
'tests/*/data/*',
'tests/PHPStan/Analyser/traits/*',
'tests/PHPStan/Generics/functions.php',
]);

$services = $containerConfigurator->services();
$services->set(DowngradeTypedPropertyRector::class);
};
7 changes: 7 additions & 0 deletions build/transform-source
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset

vendor/bin/rector process src tests/PHPStan -c build/rector-downgrade.php
3 changes: 2 additions & 1 deletion compiler/src/Console/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ private function patchFile(OutputInterface $output, string $originalFile, string

private function transformSource(): void
{
exec(escapeshellarg(__DIR__ . '/../../../bin/transform-source.php'), $outputLines, $exitCode);
chdir(__DIR__ . '/../../..');
exec(escapeshellarg(__DIR__ . '/../../../build/transform-source'), $outputLines, $exitCode);
if ($exitCode === 0) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5.4",
"rector/rector": "0.12.5",
"vaimo/composer-patches": "^4.22"
},
"config": {
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions patches/NameNodeMapper.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@package rector/rector

--- packages/StaticTypeMapper/PhpParser/NameNodeMapper.php 2021-11-23 18:38:29.000000000 +0100
+++ packages/StaticTypeMapper/PhpParser/NameNodeMapper2.php 2021-12-16 23:09:30.000000000 +0100
@@ -106,7 +106,7 @@
}
return new \Rector\StaticTypeMapper\ValueObject\Type\ParentObjectWithoutClassType();
}
- return new \PHPStan\Type\ThisType($classReflection);
+ return new \PHPStan\Type\ObjectType($classReflection->getName());
}
/**
* @return \PHPStan\Type\ArrayType|\PHPStan\Type\BooleanType|\PHPStan\Type\Constant\ConstantBooleanType|\PHPStan\Type\FloatType|\PHPStan\Type\IntegerType|\PHPStan\Type\MixedType|\PHPStan\Type\StringType
Loading

0 comments on commit 571c56d

Please sign in to comment.