diff --git a/.github/workflows/compat_tests_global.yaml.yml b/.github/workflows/compat_tests_global_phpstan.yaml similarity index 50% rename from .github/workflows/compat_tests_global.yaml.yml rename to .github/workflows/compat_tests_global_phpstan.yaml index e14d0f9..ef449ff 100644 --- a/.github/workflows/compat_tests_global.yaml.yml +++ b/.github/workflows/compat_tests_global_phpstan.yaml @@ -1,4 +1,4 @@ -name: Compat Tests for global install +name: Compat Tests for global install for PHPStan on: pull_request: null @@ -13,19 +13,13 @@ jobs: matrix: actions: - - name: 'Rector dev + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:dev-main" -W + name: 'Rector stable + PHPUnit 12 global for PHPStan' + run: composer require --dev "rector/rector:^2.2" -W php: 8.3 - - name: 'Rector stable + PHPUnit 12 global install' - run: | - composer remove --dev phpunit/phpunit -W - composer global require --dev "phpunit/phpunit:12.*" -W - composer require --dev "rector/rector:^2.2" -W + name: 'Rector dev + PHPUnit 12 global for PHPStan' + run: composer require --dev "rector/rector:dev-main" -W php: 8.3 name: ${{ matrix.actions.name }} @@ -42,10 +36,12 @@ jobs: coverage: none - uses: "ramsey/composer-install@v2" - - run: ${{ matrix.actions.run }} - - run: phpunit tests/PHPStan + - run: composer remove --dev phpunit/phpunit -W + - run: composer global require --dev "phpunit/phpunit:12.*" -W + + - run: ${{ matrix.actions.run }} - - run: phpunit tests/Rector + - run: /home/runner/.composer/vendor/bin/phpunit tests/PHPStan - - run: phpunit + - run: /home/runner/.composer/vendor/bin/phpunit diff --git a/.github/workflows/compat_tests_global_rector.yaml b/.github/workflows/compat_tests_global_rector.yaml new file mode 100644 index 0000000..bf3454a --- /dev/null +++ b/.github/workflows/compat_tests_global_rector.yaml @@ -0,0 +1,47 @@ +name: Compat Tests for global install for Rector + +on: + pull_request: null + push: + branches: + - main + +jobs: + compat_tests: + strategy: + fail-fast: false + matrix: + actions: + - + name: 'Rector stable + PHPUnit 12 global for Rector' + run: composer require --dev "rector/rector:^2.2" -W + php: 8.3 + + - + name: 'Rector dev + PHPUnit 12 global for Rector' + run: composer require --dev "rector/rector:dev-main" -W + php: 8.3 + + name: ${{ matrix.actions.name }} + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.actions.php }} + coverage: none + + - uses: "ramsey/composer-install@v2" + + - run: composer remove --dev phpunit/phpunit -W + - run: composer global require --dev "phpunit/phpunit:12.*" -W + + - run: ${{ matrix.actions.run }} + + - run: /home/runner/.composer/vendor/bin/phpunit tests/Rector + + - run: /home/runner/.composer/vendor/bin/phpunit diff --git a/src/Rector/MakeNewlineAfterIfRector.php b/src/Rector/MakeNewlineAfterIfRector.php new file mode 100644 index 0000000..8dfea09 --- /dev/null +++ b/src/Rector/MakeNewlineAfterIfRector.php @@ -0,0 +1,36 @@ +> + */ + public function getNodeTypes(): array + { + return [StmtsAwareInterface::class]; + } + + /** + * @param StmtsAwareInterface $node + * @return array|null + */ + public function refactor(Node $node): ?array + { + if (! $node instanceof If_) { + return null; + } + + return [$node, new Nop()]; + } +} diff --git a/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc b/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc new file mode 100644 index 0000000..c75675f --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/Fixture/some_if.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php b/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php new file mode 100644 index 0000000..5927b81 --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/MakeNewlineAfterIfTest.php @@ -0,0 +1,18 @@ +doTestFile(__DIR__ . '/Fixture/some_if.php.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php b/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php new file mode 100644 index 0000000..a93633c --- /dev/null +++ b/tests/Rector/MakeNewlineAfterIf/config/configured_rule.php @@ -0,0 +1,9 @@ +withRules([MakeNewlineAfterIfRector::class]);