Rector 7.0 Native init steps (#475)

This commit is contained in:
Abdul Malik Ikhsan 2021-07-21 15:29:55 +07:00 committed by GitHub
parent 9953c4f59c
commit 692e9e3db4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 949 additions and 292 deletions

View File

@ -3,13 +3,14 @@
name: Build Scoped Rector PHP 7.0
on:
# push:
# branches:
# - main
push:
branches:
- php70
# tags:
# - '*'
pull_request:
- php70-*
branches:
- php70
env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
@ -37,12 +38,29 @@ jobs:
COMPOSER_TOKEN: ${{ secrets.ACCESS_TOKEN }}
# install only prod dependencies - do not use ramsey, it uses cache including "dev", we want to avoid it here
- run: composer install --no-dev --ansi
- run: |
composer remove --dev symplify/easy-coding-standard
composer remove --dev symplify/coding-standard
composer remove composer/xdebug-handler
composer require composer/composer
composer require composer/xdebug-handler:"2.0.1 as 1.4.6"
composer install --no-dev --ansi
# early downgrade individual functions and files of symfony Attribute classes
- run: bin/rector process src/functions -c build/config/config-downgrade.php --ansi
- run: bin/rector process vendor/symfony/dependency-injection/Attribute/Autoconfigure.php -c build/config/config-downgrade.php --ansi
- run: bin/rector process vendor/symfony/dependency-injection/Attribute/AutoconfigureTag.php -c build/config/config-downgrade.php --ansi
- run: bin/rector process vendor/symfony/console/Event/ConsoleCommandEvent.php -c build/config/config-downgrade-php70.php --ansi
- run: bin/rector process vendor/symfony/console/EventListener/ErrorListener.php -c build/config/config-downgrade-php70.php --ansi
- run: wget https://github.com/box-project/box/releases/download/3.12.2/box.phar -N --no-verbose
# extra content of phpstan.phar to vendor/phpstan/phpstan-extracted
- run: php box.phar extract vendor/phpstan/phpstan/phpstan.phar vendor/phpstan/phpstan-extracted
# extra content of phpstan.phar to vendor/phpstan/phpstan-extracted and copy downgraded classes early
- run: |
php box.phar extract vendor/phpstan/phpstan/phpstan.phar vendor/phpstan/phpstan-extracted
mv vendor/phpstan/phpstan-extracted/vendor/scoper-autoload.php vendor/phpstan/phpstan-extracted/vendor/phpstan-autoload.php
cp vendor/symfony/console/Event/ConsoleCommandEvent.php vendor/phpstan/phpstan-extracted/vendor/symfony/console/Event/ConsoleCommandEvent.php
cp vendor/symfony/console/EventListener/ErrorListener.php vendor/phpstan/phpstan-extracted/vendor/symfony/console/EventListener/ErrorListener.php
# "composer remove phpstan/phpstan" original phpstan/phpstan is now duplicated, we don't need it now -required by phpstan extensions, cannot be removed like this
@ -50,6 +68,7 @@ jobs:
- run: rm -rf vendor/bin/phpstan vendor/phpstan/phpstan/bootstrap.php
# the vendor/phpstan/phpstan/bootstrap.php is statically included by composer, so better add empty file
- run: echo "<?php " > vendor/phpstan/phpstan/bootstrap.php
- run: echo "require_once __DIR__ . '/vendor/phpstan/phpstan-extracted/preload.php';" >> preload.php
- run: rm -rf vendor/phpstan/phpstan/phpstan.phar
- run: rm -rf phpstan-for-rector.neon
@ -63,8 +82,11 @@ jobs:
# 2. downgrade rector
- run: sh build/downgrade-rector-php70.sh rector-build-php70
# 3. prefix classes
- run: sh build/build-rector-scoped-php70.sh rector-build-php70 rector-prefixed-downgraded-php70
# 3. prefix classes and manual downgrade after prefixed for individual IgnoredRegexValidator.php
- run: |
sh build/build-rector-scoped-php70.sh rector-build-php70 rector-prefixed-downgraded-php70
bin/rector process rector-prefixed-downgraded-php70/vendor/phpstan/phpstan-extracted/src/Command/IgnoredRegexValidator.php -c build/config/config-downgrade-php70.php --ansi
bin/rector process build/target-repository-php70/bootstrap.php -c build/config/config-downgrade-php70.php --ansi
# 4. lint the code for PHP 7.0 - this must happen here, as setup-php allows only one PHP version switch: https://github.com/shivammathur/setup-php/issues/434
-
@ -73,18 +95,17 @@ jobs:
php-version: 7.0
coverage: none
- run: |
rm -rf vendor && mkdir -p vendor
cp -R rector-prefixed-downgraded-php70/vendor/* vendor/
rm -rf php-parallel-lint
rm -rf vendor
composer create-project php-parallel-lint/php-parallel-lint php-parallel-lint --ansi
- run: php-parallel-lint/parallel-lint rector-prefixed-downgraded-php70 --exclude rector-prefixed-downgraded-php70/stubs --exclude rector-prefixed-downgraded-php70/vendor/symfony/error-handler/Resources --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-kernel/Resources --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/polyfill-mbstring/bootstrap80.php --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symplify/smart-file-system/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Session --exclude rector-prefixed-downgraded-php70/vendor/symfony/var-dumper --exclude rector-prefixed-downgraded-php70/vendor/nette/caching --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/src/Rector/LNumber --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Test --exclude rector-prefixed-downgraded-php70/vendor/symplify/simple-php-doc-parser/tests --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/src/Tracy/Bar/panels/info.panel.phtml --exclude rector-prefixed-downgraded-php70/vendor/symfony/string/Slugger/AsciiSlugger.php
- run: php-parallel-lint/parallel-lint rector-prefixed-downgraded-php70 --exclude rector-prefixed-downgraded-php70/stubs --exclude rector-prefixed-downgraded-php70/vendor/symfony/error-handler/Resources --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-kernel/Resources --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/polyfill-mbstring/bootstrap80.php --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symplify/smart-file-system/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Session --exclude rector-prefixed-downgraded-php70/vendor/symfony/var-dumper --exclude rector-prefixed-downgraded-php70/vendor/nette/caching --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/src/Rector/LNumber --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Test --exclude rector-prefixed-downgraded-php70/vendor/symplify/simple-php-doc-parser/tests --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/src/Tracy/Bar/panels/info.panel.phtml --exclude rector-prefixed-downgraded-php70/vendor/rector/extension-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/string/Slugger/AsciiSlugger.php --exclude rector-prefixed-downgraded-php70/vendor/ssch/typo3-rector/templates/maker
# 5. copy repository meta files
# 5. downgrade bootstrap.php and copy repository meta files
- run: |
cp -R build/target-repository-php70/. rector-prefixed-downgraded-php70
cp -R templates rector-prefixed-downgraded-php70/
cp CONTRIBUTING.md rector-prefixed-downgraded-php70/
cp -R preload.php rector-prefixed-downgraded-php70/
# 6. clone remote repository, so we can push it
-
@ -96,7 +117,6 @@ jobs:
# remove remote files, to avoid piling up dead code in remote repository
- run: rm -rf remote-repository-php70/config remote-repository-php70/src remote-repository-php70/rules remote-repository-php70/packages remote-repository-php70/vendor
- run: cp -a rector-prefixed-downgraded-php70/. remote-repository-php70
# 7. setup git

View File

@ -39,6 +39,7 @@ if (file_exists($extractedPhpstanAutoload)) {
require_once __DIR__ . '/../src/constants.php';
$autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/phpstan/phpstan-extracted/vendor/phpstan-autoload.php');
$autoloadIncluder->loadIfExistsAndNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php');
$autoloadIncluder->autoloadProjectAutoloaderFile();
@ -121,6 +122,7 @@ final class AutoloadIncluder
public function loadIfExistsAndNotLoadedYet(string $filePath): void
{
// the scoper-autoload.php is exists in phpstan-extracted/vendor/scoper-autoload.php, move the check in :
if (! file_exists($filePath)) {
return;
}

View File

@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
$phpStanStubLoader = new PHPStanStubLoader();
$phpStanStubLoader->loadStubs();
require_once __DIR__ . '/../../stubs-rector/PHPUnit/Framework/TestCase.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
@ -36,10 +38,6 @@ final class DowngradeRectorConfig
// symfony test are parts of package
'*/Test/*',
// missing phpunit test case
'packages/Testing/PHPUnit/AbstractRectorTestCase.php',
'packages/Testing/PHPUnit/AbstractComposerRectorTestCase.php',
// only for dev
'packages/Testing/PhpConfigPrinter/*',
@ -50,7 +48,6 @@ final class DowngradeRectorConfig
// use relative paths, so files are excluded on nested directory too
'vendor/symfony/http-kernel/HttpKernelBrowser.php',
'vendor/symfony/http-foundation/Session/*',
'vendor/symfony/string/Slugger/AsciiSlugger.php',
'vendor/symfony/cache/*',
'nette/caching/src/Bridges/*',

View File

@ -27,8 +27,16 @@ export IFS=";"
# 4. downgrade the directories
for directory in $directories; do
echo "[NOTE] Downgrading '$directory' directory\n"
if [ -f $directory ]; then
echo "[NOTE] Downgrading '$directory' file\n"
else
echo "[NOTE] Downgrading '$directory' directory\n"
fi
# --working-dir is needed, so "SKIP" parameter is applied in absolute path of nested directory
php -d memory_limit=-1 bin/rector process $directory --config build/config/config-downgrade-php70.php --working-dir $BUILD_DIRECTORY --ansi
done
# CONFIRMED: give time to print all the files, before the next process takes over newly printed content
# avoids bugs like these half of files done, next half waiting https://github.com/rectorphp/rector-src/runs/2565478682
sleep 40

View File

@ -0,0 +1,27 @@
################################################
## Docker image used for profiling Rector ##
################################################
ARG PHP_VERSION=8.0
FROM rector/rector:php${PHP_VERSION}
# Install php extensions
RUN apt-get update && apt-get install -y \
wget \
gnupg2
# Setup blackfire repo
RUN wget -q -O - https://packages.blackfire.io/gpg.key | apt-key add -
RUN echo "deb http://packages.blackfire.io/debian any main" | tee /etc/apt/sources.list.d/blackfire.list
# Install blackfire php extensions
RUN apt-get update && apt-get install -y \
blackfire-php
# Install blackfire cli tool
RUN mkdir -p /tmp/blackfire \
&& architecture=$(case $(uname -m) in i386 | i686 | x86) echo "i386" ;; x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \
&& curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux/$architecture | tar zxp -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire /usr/bin/blackfire \
&& rm -Rf /tmp/blackfire

View File

@ -0,0 +1,34 @@
## Docker image for Blackfire profiling
### Build
Builds image with `rector-blackfire` tag.
```
docker build . --tag rector-blackfire --file .docker/php-blackfire/Dockerfile
```
You can use `--build-arg PHP_VERSION=7.4` to build with specific PHP version. Supported versions are: 7.3, 7.4, 8.0
### Prepare
These variables must be set on host to pass them into container (obtain values at [blackfire.io](https://blackfire.io)):
```
export BLACKFIRE_CLIENT_ID=""
export BLACKFIRE_CLIENT_TOKEN=""
```
### Usage
Get into container:
```
docker run --entrypoint="" -it --rm -e BLACKFIRE_CLIENT_ID -e BLACKFIRE_CLIENT_TOKEN -v $(pwd):/rector rector-blackfire bash
```
Once in container, you can start profiling:
```
blackfire run php bin/rector <args..>
```

View File

@ -0,0 +1,11 @@
################################################
## Docker image used for debugging Rector ##
################################################
ARG PHP_VERSION=8.0
FROM rector/rector:php${PHP_VERSION}
RUN pecl install xdebug
COPY .docker/php-xdebug/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini

View File

@ -0,0 +1,26 @@
## Docker image for Xdebug debugging
### Build
Builds image with `rector-xdebug` tag.
```shell
docker build . --tag rector-xdebug --file .docker/php-xdebug/Dockerfile
```
You can use `--build-arg PHP_VERSION=7.4` to build with specific PHP version. Supported versions are: 7.3, 7.4, 8.0
### Usage
Get into container (change ip address):
```shell
docker run -it --rm \
--entrypoint="" \
--volume $(pwd):/rector \
--env XDEBUG_CONFIG="client_host=172.16.165.1" \
--env PHP_IDE_CONFIG="serverName=rector" \
rector-xdebug bash
```
**Do not forget to run rector binary with `--xdebug` option.**

View File

@ -0,0 +1,5 @@
[xdebug]
zend_extension = "/usr/local/lib/php/extensions/no-debug-non-zts-20200930/xdebug.so"
xdebug.mode = debug
xdebug.client_port = 9003
xdebug.start_with_request = yes

View File

@ -0,0 +1,10 @@
[opcache]
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.enable=1
opcache.file_cache='/tmp/opcache'
opcache.file_update_protection=0

View File

@ -0,0 +1,28 @@
*~ 
.DS_Store
.idea/
.env
.editorconfig
.phpstorm.meta.php
phpstan.neon
rector.php
phpunit.xml
ecs.php
LICENSE
.gitattributes
.gitignore
*.md
.dockerignore
Dockerfile
docker-compose.yml
docker-compose.dist.yml
/docs
*.phar

View File

@ -0,0 +1,29 @@
# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
# Set syntax highlight on GitHub
# https://github.com/github/linguist/blob/master/lib/linguist/languages.yml
*.neon linguist-language=YAML
# Remove files for archives generated using `git archive`
.editorconfig export-ignore
.gitattributes export-ignore
CONTRIBUTING.md export-ignore
CHANGELOG.md export-ignore
CODE_OF_CONDUCT.md export-ignore
# exclude only root dirs, otherwise nette/utils is removed - see https://github.com/TomasVotruba/tomasvotruba.com/pull/1197/checks?check_run_id=2577329283
/stubs export-ignore
Dockerfile export-ignore
docs/images export-ignore
.docker export-ignore
.github export-ignore
e2e export-ignore
.dockerignore export-ignore
# testing Windows spaces - https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings
packages/better-php-doc-parser/tests/PhpDocInfo/PhpDocInfoPrinter/FixtureBasic/with_spac.txt text eol=crlf

View File

@ -0,0 +1 @@
github: tomasvotruba

View File

@ -0,0 +1,24 @@
---
name: Bug Report
labels: bug
about: Report errors and problems
---
# Bug Report
<!-- First, thank you for reporting a bug. That takes time and we appreciate that! -->
| Subject | Details |
| :------------- | :---------------------------------------------------------------|
| Rector version | e.g. v0.9.5 (invoke `vendor/bin/rector --version`) |
| Installed as | composer dependency / prefixed Rector |
<!-- Please describe your problem here. -->
## Minimal PHP Code Causing Issue
<!-- Reproduce the issue using https://getrector.org/demo/ and post the URL here. -->
## Expected Behaviour
<!-- How should Rector change the code? Or should Rector skip it? -->

View File

@ -0,0 +1,18 @@
---
name: Feature Request
labels: feature
about: RFC and ideas for new features and improvements
---
# Feature Request
<!-- First, thank you for making a request. That takes time and we appreciate that! -->
## Diff
<!-- Use diff here in Markdown: https://stackoverflow.com/a/40883538/1348344 -->
```diff
-$value = $value + 5;
+$value += 5;
```

View File

@ -0,0 +1,7 @@
---
name: Support Question
labels: support
about: Questions about using this library
---
# Question

View File

@ -0,0 +1,14 @@
name: Auto Closer PR
on:
pull_request_target:
types: [opened]
jobs:
run:
runs-on: ubuntu-latest
steps:
- uses: superbrothers/close-pull-request@v3
with:
# Optional. Post a issue comment just before closing a pull request.
comment: "This repository content is generated by rectorphp/rector-src. Please open pull request to [rectorphp/rector-src](https://github.com/rectorphp/rector-src)."

View File

@ -24,4 +24,6 @@ jobs:
php-version: ${{ matrix.php_version }}
coverage: none
- run: php bin/rector --version --ansi
- run: php bin/rector list --ansi

View File

@ -0,0 +1,42 @@
# This workflow runs system tests: Use the Rector application from the source
# checkout to process "fixture" projects in tests/system-tests
# to see if those can be processed successfully
name: End to End tests
on:
pull_request: null
push:
branches:
- main
jobs:
end_to_end:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0']
directory:
- 'e2e/attributes'
- 'e2e/dont-execute-code'
- 'e2e/finalize'
- 'e2e/parse-php7-code'
- 'e2e/parse-php8-code'
name: End to end test - ${{ matrix.directory }}
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
coverage: none
-
run: composer install --ansi
working-directory: ${{ matrix.directory }}
-
run: ../../bin/rector process --dry-run --ansi
working-directory: ${{ matrix.directory }}

View File

@ -1,60 +0,0 @@
name: Rector Run
on:
pull_request: null
push:
branches:
- main
jobs:
rector_run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version: ['7.0', 7.1', '7.2', '7.3', '7.4', '8.0']
commands:
-
name: 'Finalize Entity'
install: composer require doctrine/orm
run: vendor/bin/rector process ../tests/fixture-finalize --config ../ci/rector-finalize.php --ansi
-
name: 'Composer Dependency'
install: composer require symfony/console 2.8
run: vendor/bin/rector list --debug --ansi
-
name: 'Along PHPStan'
install: composer require phpstan/phpstan --dev --ansi
run: |
vendor/bin/rector list --ansi
vendor/bin/phpstan -h --ansi
name: "PHP ${{ matrix.php_version }}"
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
coverage: none
- run: |
mkdir standalone
cd standalone
# wait for deploy to packagist
sleep 70
- run: |
cd standalone
# run
composer require rector/rector:dev-main --dev --ansi
${{ matrix.commands.install }}
-
run: |
cd standalone
${{ matrix.commands.run }}

View File

@ -1,21 +0,0 @@
name: PHP 8 Attributes
on:
pull_request: null
push:
branches:
- main
jobs:
php8_attributes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
coverage: none
- run: bin/rector process tests/fixture-php8-attributes --config ci/rector-attributes.php --ansi

View File

@ -0,0 +1,64 @@
name: Build docker images
on:
push:
# Publish `main` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags:
- '*'
env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: "dev-main"
jobs:
publish_images:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build images
run: |
DOCKER_TAGS=""
# Pull tag and branch from github.ref, which is either refs/heads/... or refs/tags/...
TAG=$(echo "${{ github.ref }}" | sed -e '/refs\/tags\//!d; s,refs/.*/v\?\(.*\),\1,')
BRANCH=$(echo "${{ github.ref }}" | sed -e '/refs\/heads\//!d; s,refs/.*/\(.*\),\1,')
if [ "main" == "$BRANCH" ]; then
DOCKER_TAGS="$DOCKER_TAGS latest"
fi
if [ ! -z "$TAG" ]; then
DOCKER_TAGS="$DOCKER_TAGS $TAG"
fi
echo "Image will be tagged with: $DOCKER_TAGS"
DOCKER_TAG_ARG=""
for ARG in $DOCKER_TAGS; do
DOCKER_TAG_ARG="$DOCKER_TAG_ARG --tag rector/rector:$ARG"
done
docker buildx create --name builder-php8 --use
docker buildx build \
--progress plain \
--cache-from=rector/rector:build-cache-php8 \
--cache-to=type=registry,ref=rector/rector:build-cache-php8,mode=max,push=true \
--target rector \
--push \
$DOCKER_TAG_ARG \
--platform linux/amd64,linux/arm64 \
--build-arg PHP_VERSION=8 .

View File

@ -1,22 +0,0 @@
name: Simple Test
on:
pull_request: null
push:
branches:
- main
jobs:
simple_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
-
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
- run: composer require phpunit/phpunit --dev
- run: vendor/bin/phpunit tests/Rector/RenameSimpleRectorTest.php

View File

@ -0,0 +1,37 @@
name: Standalone Rule Test
on:
pull_request: null
push:
branches:
- main
jobs:
standalone_rule_test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
actions:
-
name: 'Rector Prefixed'
run: composer require rector/rector:dev-main --dev
steps:
# see https://github.com/rectorphp/rector-prefixed-rule-test
-
uses: actions/checkout@v2
with:
repository: rectorphp/rector-prefixed-rule-test
- uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
coverage: none
- uses: "ramsey/composer-install@v1"
- run: ${{ matrix.actions.run }}
- run: vendor/bin/phpunit

View File

@ -0,0 +1,58 @@
ARG PHP_VERSION=8.0
FROM php:${PHP_VERSION}-cli as base
RUN apt-get update && apt-get install -y \
libzip4 \
libicu63 \
&& rm -rf /var/lib/apt/lists/*
FROM base as build
WORKDIR /rector
# Install php extensions
RUN apt-get update && apt-get install -y \
g++ \
git \
libicu-dev \
libzip-dev \
unzip \
wget \
zip \
&& pecl -q install \
zip \
&& docker-php-ext-configure intl \
&& docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install \
intl \
opcache \
zip
# Add source
COPY . .
# Build runtime image
FROM base as rector
COPY --from=build /usr/local/lib/php /usr/local/lib/php
COPY --from=build /usr/local/etc/php /usr/local/etc/php
COPY .docker/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
ENV PATH /rector/bin:$PATH
# Add source
COPY . /rector
ENTRYPOINT [ "rector" ]
VOLUME ["/project"]
WORKDIR "/project"
RUN mkdir -p /tmp/opcache
RUN chmod +x /rector/bin/rector
RUN /rector/bin/rector list
RUN mkdir -p /tmp/opcache \
&& /rector/bin/rector list \
&& chmod 777 -R /tmp

View File

@ -1,11 +1,54 @@
# Prefixed Rector
# Rector - Instant Upgrades and Automated Refactoring
[![Build Status Github Actions](https://img.shields.io/github/workflow/status/rectorphp/rector-prefixed/Code_Checks?style=flat-square)](https://github.com/rectorphp/rector-prefixed/actions)
[![Downloads](https://img.shields.io/packagist/dt/rector/rector.svg?style=flat-square)](https://packagist.org/packages/rector/rector-prefixed)
[![Downloads](https://img.shields.io/packagist/dt/rector/rector.svg?style=flat-square)](https://packagist.org/packages/rector/rector)
Do you have conflicts on Rector install? You're in the right place. Prefixed Rector can [be installed even on very old Symfony](https://getrector.org/blog/2020/01/20/how-to-install-rector-despite-composer-conflicts).
<br>
Do you have older PHP? Rector prefixed goes down to PHP 7.0, so you can install it even on older projects.
Rector instantly upgrades and refactors the PHP code of your application. It can help you 2 major areas:
### 1. Instant Upgrades
Rector now supports upgrades from PHP 5.3 to 8.0 and major open-source projects like [Symfony](https://github.com/rectorphp/rector-symfony), [PHPUnit](https://github.com/rectorphp/rector-phpunit), [Nette](https://github.com/rectorphp/rector-nette), [Laravel](https://github.com/rectorphp/rector-laravel), [CakePHP](https://github.com/rectorphp/rector-cakephp), [Doctrine](https://github.com/rectorphp/rector-doctrine) and [Typo3](https://github.com/sabbelasichon/typo3-rector) out of the box. Do you want to **be constantly on the latest PHP/framework version without effort**?
Use Rector to handle **instant upgrades** for you.
### 2. Automated Refactoring
Do you have code quality you need, but struggle to keep it with new developers in your team? Do you want see smart code-reviews even when every senior developers sleeps?
Add Rector to your CI and let it **continuously refactor your code** and keep the code quality high.
<br>
## Read a First Book About Rector
Are you curious, how Rector works internally, how to create your own rules and test them and why Rector was born? In May 2021 we've released the very first book: *Rector - The Power of Automated Refactoring*.
<a href="https://leanpub.com/rector-the-power-of-automated-refactoring">
<img src="https://github.com/rectorphp/the-power-of-automated-refactoring-feedback/raw/main/images/book_title.png">
</a>
By [buying a book](https://leanpub.com/rector-the-power-of-automated-refactoring) you directly support maintainers who are working on Rector.
<br>
## Documentation
- [Explore 450+ Rector Rules](/docs/rector_rules_overview.md)
- [Auto Import Names](/docs/auto_import_names.md)
- [How to Ignore Rule or Paths](/docs/how_to_ignore_rule_or_paths.md)
- [Static Reflection and Autoload](/docs/static_reflection_and_autoload.md)
- [How to Configure Rule](/docs/how_to_configure_rules.md)
### For Rule Developers and Contributors
- [How Does Rector Work?](/docs/how_it_works.md)
- [PHP Parser Nodes](https://github.com/rectorphp/php-parser-nodes-docs/)
- [How to Work with Doc Block and Comments](/docs/how_to_work_with_doc_block_and_comments.md)
- [How to Generate New Rector Rule](/docs/create_own_rule.md)
- [How to add Test for Rector Rule](/docs/how_to_add_test_for_rector_rule.md)
<br>
## Install
@ -13,13 +56,136 @@ Do you have older PHP? Rector prefixed goes down to PHP 7.0, so you can install
composer require rector/rector --dev
```
<br>
## Running Rector
There a 2 main ways to use Rector:
- a *single rule*, to have the change under control
- or group of rules called *sets*
To use them, create a `rector.php` in your root directory:
```bash
# generate "rector.php" config
vendor/bin/rector init
```
# dry run
And modify it:
```php
// rector.php
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
// here we can define, what sets of rules will be applied
// tip: use "SetList" class to autocomplete sets
$containerConfigurator->import(SetList::CODE_QUALITY);
// register single rule
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
};
```
Then dry run Rector:
```bash
vendor/bin/rector process src --dry-run
```
# changing run
Rector will show you diff of files that it *would* change. To *make* the changes, drop `--dry-run`:
```bash
vendor/bin/rector process src
```
*Note: `rector.php` is loaded by default. For different location, use `--config` option.*
<br>
## Configuration
```php
// rector.php
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
// is your PHP version different from the one your refactor to? [default: your PHP version], uses PHP_VERSION_ID format
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_72);
// Run Rector only on changed files
$parameters->set(Option::ENABLE_CACHE, true);
// Path to phpstan with extensions, that PHPSTan in Rector uses to determine types
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, getcwd() . '/phpstan-for-config.neon');
};
```
<br>
## Support
Rector is a tool that [we develop](https://getrector.org/) and share for free, so anyone can automate their refactoring. But not everyone has dozens of hours to understand complexity of abstract-syntax-tree in their own time. **That's why we provide commercial support - to save your time**.
Would you like to apply Rector on your code base but don't have time for the struggle with your project? [Hire us](https://getrector.org/contact) to get there faster.
<br>
## How to Contribute
See [the contribution guide](/CONTRIBUTING.md).
<br>
## Debugging
You can use `--debug` option, that will print nested exceptions output:
```bash
vendor/bin/rector process src/Controller --dry-run --debug
```
Or with Xdebug:
1. Make sure [Xdebug](https://xdebug.org/) is installed and configured
2. Add `--xdebug` option when running Rector
```bash
vendor/bin/rector process src/Controller --dry-run --xdebug
```
To assist with simple debugging Rector provides a 2 helpers to pretty-print AST-nodes:
```php
use PhpParser\Node\Scalar\String_;
$node = new String_('hello world!');
// prints node to string, as PHP code displays it
print_node($node);
// dump nested node object with nested properties
dump_node($node);
// 2nd argument is how deep the nesting is - this makes sure the dump is short and useful
dump_node($node, 1);
```
<br>
## Known Drawbacks
### How to Apply Coding Standards?
Rector uses [nikic/php-parser](https://github.com/nikic/PHP-Parser/), built on technology called an *abstract syntax tree* (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations. **That's why your project needs to have a coding standard tool** and a set of formatting rules, so it can make Rector's output code nice and shiny again.
We're using [ECS](https://github.com/symplify/easy-coding-standard) with [this setup](ecs.php).

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types = 1);
// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php
spl_autoload_register(function (string $class): void {
static $composerAutoloader;
// already loaded in bin/rector.php
if (defined('__RECTOR_RUNNING__')) {
return;
}
// load prefixed or native class, e.g. for running tests
if (strpos($class, 'RectorPrefix') === 0 || strpos($class, 'Rector\\') === 0) {
if ($composerAutoloader === null) {
// prefixed version autoload
$composerAutoloader = require __DIR__ . '/vendor/autoload.php';
}
$composerAutoloader->loadClass($class);
}
// aliased by php-scoper, that's why its missing
if ($class === 'Symplify\SmartFileSystem\SmartFileInfo') {
$filePath = __DIR__ . '/vendor/symplify/smart-file-system/src/SmartFileInfo.php';
if (file_exists($filePath)) {
require $filePath;
}
}
if ($class === 'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator') {
// avoid duplicated autoload bug in Rector demo runner
if (class_exists('Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator', false)) {
return;
}
}
});

View File

@ -1,5 +1,5 @@
{
"name": "rector/rector-php70",
"name": "rector/rector",
"description": "Prefixed and PHP 7.0 downgraded version of rector/rector",
"license": "MIT",
"bin": [
@ -12,5 +12,16 @@
"branch-alias": {
"dev-main": "0.10-dev"
}
},
"conflict": {
"phpstan/phpdoc-parser": "<=0.5.3",
"phpstan/phpstan": "<=0.12.82",
"rector/rector-prefixed": "*",
"rector/rector-phpunit": "*",
"rector/rector-symfony": "*",
"rector/rector-doctrine": "*",
"rector/rector-nette": "*",
"rector/rector-nette-to-symfony": "*",
"rector/rector-cakephp": "*"
}
}

View File

@ -0,0 +1,5 @@
{
"autoload-dev": {
"directories": ["stubs"]
}
}

View File

@ -7,12 +7,10 @@ use Rector\Core\ValueObject\PhpVersion;
use Rector\Symfony\Set\SymfonySetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
// route class must exist and be loaded, as annotation parser uses dynamic reflection
require_once __DIR__ . '/../stubs/Symfony/Component/Routing/Annotation/Route.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->import(SymfonySetList::SYMFONY_52);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
$parameters->set(Option::SOURCE, [__DIR__ . '/src']);
};

View File

@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"Symfony\\Component\\Console\\Output\\": "src"
}
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__.'/src']);
$containerConfigurator->import(SetList::PHP_53);
};

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
final class OutputInterface
{
}

View File

@ -0,0 +1,10 @@
{
"autoload": {
"psr-4": {
"Rector\\e2e\\": "src"
}
},
"require-dev": {
"doctrine/orm": "^2.7"
}
}

View File

@ -2,7 +2,6 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\RectorPrefixed\Tests;
namespace Rector\e2e;
use Doctrine\ORM\Mapping as ORM;

View File

@ -2,7 +2,7 @@
declare(strict_types=1);
namespace Rector\RectorPrefixed\Tests;
namespace Rector\e2e;
class SomeClassWithoutChildren
{

View File

@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"Foo\\": "src"
}
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__.'/src']);
$containerConfigurator->import(SetList::PHP_53);
};

View File

@ -0,0 +1,12 @@
<?php
namespace Foo;
class Foo
{
public function __construct()
{
$bar = 'baz';
print $bar{2};
}
}

View File

@ -0,0 +1,7 @@
{
"autoload": {
"psr-4": {
"Foo\\": "src"
}
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PATHS, [__DIR__.'/src']);
$containerConfigurator->import(SetList::PHP_53);
};

View File

@ -0,0 +1,10 @@
<?php
namespace Foo;
class Foo
{
public function __construct(
public string $property = 'value',
) {}
}

View File

@ -1,7 +0,0 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
>
</phpunit>

View File

@ -1,11 +0,0 @@
<?php
$value = 1000;
?>
-----
<?php
$newValue = 1000;
?>

View File

@ -1,34 +0,0 @@
<?php
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \RenameSimpleRectorTest
*/
final class RenameSimpleRector extends AbstractRector
{
/**
* @return array<class-string<\PhpParser\Node>>
*/
public function getNodeTypes(): array
{
return [Variable::class];
}
/**
* @param Variable $node
*/
public function refactor(Node $node): ?Node
{
$node->name = 'newValue';
return $node;
}
public function getRuleDefinition(): RuleDefinition
{
// ...
}
}

View File

@ -1,28 +0,0 @@
<?php
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class RenameSimpleRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
/**
* @return Iterator<SmartFileInfo>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}

View File

@ -1,10 +0,0 @@
<?php
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(RenameSimpleRector::class);
};

View File

@ -1,4 +0,0 @@
<?php
require_once __DIR__ . '/Rector/RenameSimpleRector.php';
require_once __DIR__ . '/Rector/RenameSimpleRectorTest.php';

61
full_build_php70.sh Normal file
View File

@ -0,0 +1,61 @@
#!/usr/bin/env bash
# see https://stackoverflow.com/questions/66644233/how-to-propagate-colors-from-bash-script-to-github-action?noredirect=1#comment117811853_66644233
export TERM=xterm-color
# show errors
set -e
# script fails if trying to access to an undefined variable
set -u
rm -rf vendor
rm -rf composer.lock
composer remove composer/xdebug-handler
composer require composer/composer
composer require composer/xdebug-handler:"2.0.1 as 1.4.6"
composer install --no-dev --ansi
bin/rector process vendor/symfony/console/Event/ConsoleCommandEvent.php -c build/config/config-downgrade-php70.php --ansi
bin/rector process vendor/symfony/console/EventListener/ErrorListener.php -c build/config/config-downgrade-php70.php --ansi
wget https://github.com/box-project/box/releases/download/3.12.2/box.phar -N --no-verbose
php box.phar extract vendor/phpstan/phpstan/phpstan.phar vendor/phpstan/phpstan-extracted
cp vendor/symfony/console/Event/ConsoleCommandEvent.php vendor/phpstan/phpstan-extracted/vendor/symfony/console/Event/ConsoleCommandEvent.php
cp vendor/symfony/console/EventListener/ErrorListener.php vendor/phpstan/phpstan-extracted/vendor/symfony/console/EventListener/ErrorListener.php
rm -rf vendor/bin/phpstan vendor/phpstan/phpstan/bootstrap.php
echo "<?php " > vendor/phpstan/phpstan/bootstrap.php
rm -rf vendor/phpstan/phpstan/phpstan.phar
rm -rf phpstan-for-rector.neon
rsync --exclude rector-build-php70 -av * rector-build-php70 --quiet
rm -rf rector-build-php70/packages-tests rector-build-php70/rules-tests rector-build-php70/tests
bin/rector list --debug
sh build/downgrade-rector-php70.sh rector-build-php70
git checkout phpstan-for-rector.neon
git checkout composer.json
sh build/build-rector-scoped-php70.sh rector-build-php70 rector-prefixed-downgraded-php70
bin/rector process rector-prefixed-downgraded-php70/vendor/phpstan/phpstan-extracted/src/Command/IgnoredRegexValidator.php -c build/config/config-downgrade-php70.php --ansi
bin/rector process build/target-repository-php70/bootstrap.php -c build/config/config-downgrade-php70.php --ansi
rm -rf php-parallel-lint
mv vendor vendor-backup
rm -rf rector-build-php70
/opt/homebrew/opt/php@7.0/bin/php /usr/local/bin/composer create-project php-parallel-lint/php-parallel-lint php-parallel-lint --ansi
/opt/homebrew/opt/php@7.0/bin/php php-parallel-lint/parallel-lint rector-prefixed-downgraded-php70 --exclude rector-prefixed-downgraded-php70/stubs --exclude rector-prefixed-downgraded-php70/vendor/symfony/error-handler/Resources --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-kernel/Resources --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/polyfill-mbstring/bootstrap80.php --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/examples --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symplify/smart-file-system/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Session --exclude rector-prefixed-downgraded-php70/vendor/symfony/var-dumper --exclude rector-prefixed-downgraded-php70/vendor/nette/caching --exclude rector-prefixed-downgraded-php70/vendor/rector/rector-nette/src/Rector/LNumber --exclude rector-prefixed-downgraded-php70/vendor/symfony/http-foundation/Test --exclude rector-prefixed-downgraded-php70/vendor/symplify/simple-php-doc-parser/tests --exclude rector-prefixed-downgraded-php70/vendor/tracy/tracy/src/Tracy/Bar/panels/info.panel.phtml --exclude rector-prefixed-downgraded-php70/vendor/rector/extension-installer/tests --exclude rector-prefixed-downgraded-php70/vendor/symfony/string/Slugger/AsciiSlugger.php --exclude rector-prefixed-downgraded-php70/vendor/ssch/typo3-rector/templates/maker
mv vendor-backup vendor
cp -R build/target-repository-php70/. rector-prefixed-downgraded-php70
cp -R templates rector-prefixed-downgraded-php70/
rm -rf rector-prefixed-downgraded-php70

View File

@ -31,6 +31,21 @@ $filePathsToRemoveNamespace = [
$dateTime = DateTime::from('now');
$timestamp = $dateTime->format('Ymd');
/**
* @var array<string, string[]>
*/
const UNPREFIX_CLASSES_BY_FILE = [
// make UT=1 in tests work
'packages/Testing/PHPUnit/AbstractRectorTestCase.php' => [
'PHPUnit\Framework\ExpectationFailedException',
'PHPUnit\Framework\TestCase',
],
// unprefixed ComposerJson as part of public API in ComposerRectorInterface
'rules/Composer/Contract/Rector/ComposerRectorInterface.php' => ['Symplify\ComposerJsonManipulator\ValueObject\ComposerJson'],
'packages/Testing/PHPUnit/AbstractTestCase.php' => ['PHPUnit\Framework\TestCase'],
];
// see https://github.com/humbug/php-scoper
return [
ScoperOption::PREFIX => 'RectorPrefix' . $timestamp,
@ -52,6 +67,25 @@ return [
return $content;
},
function (string $filePath, string $prefix, string $content): string {
foreach (UNPREFIX_CLASSES_BY_FILE as $endFilePath => $unprefixClasses) {
if (! Strings::endsWith($filePath, $endFilePath)) {
continue;
}
foreach ($unprefixClasses as $unprefixClass) {
$doubleQuotedClass = preg_quote('\\' . $unprefixClass);
$content = Strings::replace(
$content,
'#' . $prefix . $doubleQuotedClass . '#',
$unprefixClass
);
}
}
return $content;
},
// unprefixed SmartFileInfo
function (string $filePath, string $prefix, string $content): string {
return Strings::replace(
@ -61,26 +95,19 @@ return [
);
},
// unprefixed ContainerConfigurator
function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/')) {
// keep vendor prefixed the prefixed file loading; not part of public API
// except @see https://github.com/symfony/symfony/commit/460b46f7302ec7319b8334a43809523363bfef39#diff-1cd56b329433fc34d950d6eeab9600752aa84a76cbe0693d3fab57fed0f547d3R110
if (str_contains($filePath, 'vendor/symfony') && ! str_ends_with($filePath, 'vendor/symfony/dependency-injection/Loader/PhpFileLoader.php')) {
return $content;
}
// see https://regex101.com/r/PDGN3K/1
$content = Strings::replace(
$content, '
#: \?\\\\.*#',
''
return Strings::replace(
$content,
'#' . $prefix . '\\\\Symfony\\\\Component\\\\DependencyInjection\\\\Loader\\\\Configurator\\\\ContainerConfigurator#',
'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator'
);
// see https://regex101.com/r/P7nbpU/1
$content = Strings::replace(
$content, '
#\(\?\\.*\s+#',
'('
);
return $content;
},
// get version for prefixed version
@ -91,8 +118,8 @@ return [
// @see https://regex101.com/r/gLefQk/1
return Strings::replace(
$content, '#\(\'rector\/rector\'\)#',
"('rector/rector-prefixed')"
$content, '#\(\'rector\/rector-src\'\)#',
"('rector/rector')"
);
},
@ -106,6 +133,16 @@ return [
return Strings::replace($content, '#' . $prefix . '\\\\Composer\\\\#', 'Composer\\');
},
// un-prefix phpstan-extracted Composer\Autoload\ClassLoader
function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/phpstan/phpstan-extracted/')) {
return $content;
}
// see https://regex101.com/r/1l9oxm/1
return Strings::replace($content, '#' . $prefix . '\\\\Composer\\\\Autoload\\\\\ClassLoader#', 'Composer\\Autoload\\ClassLoader');
},
// fixes https://github.com/rectorphp/rector/issues/6007
function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/')) {
@ -127,23 +164,6 @@ return [
return $content;
},
function (string $filePath, string $prefix, string $content): string {
if (
! Strings::endsWith($filePath, 'packages/Testing/PHPUnit/AbstractTestCase.php')
&& ! Strings::endsWith($filePath, 'packages/Testing/PHPUnit/AbstractRectorTestCase.php')
) {
return $content;
}
// un-prefix
return Strings::replace(
$content,
'#' . $prefix . '\\\\PHPUnit\\\\Framework\\\\TestCase#',
'PHPUnit\Framework\TestCase'
);
},
// fixes https://github.com/rectorphp/rector/issues/6010 + test case prefix
function (string $filePath, string $prefix, string $content): string {
// @see https://regex101.com/r/bA1nQa/1
@ -156,30 +176,6 @@ return [
return Strings::replace($content, $namespace);
},
function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/')) {
return $content;
}
// @see https://regex101.com/r/wcAbLf/1
return Strings::replace(
$content, '#((private|public|protected)\s+const)#',
"const"
);
},
function (string $filePath, string $prefix, string $content): string {
if (! Strings::contains($filePath, 'vendor/')) {
return $content;
}
// @see https://regex101.com/r/r3AJFl/1
return Strings::replace(
$content, '#\)\s{0,}:\s{0,}void#',
")"
);
},
// unprefix string classes, as they're string on purpose - they have to be checked in original form, not prefixed
function (string $filePath, string $prefix, string $content): string {
// skip vendor, expect rector packages
@ -207,6 +203,11 @@ return [
return $content;
}
// skip "Ssch\\" namespace
if (Strings::contains($content, '$services->load(\'Ssch')) {
return $content;
}
return Strings::replace($content, '#services\->load\(\'#', 'services->load(\'' . $prefix . '\\');
},
],

View File

@ -44,7 +44,8 @@ final class PHPStanStubLoader
}
foreach (self::STUBS as $stub) {
$path = sprintf('phar://%s/phpstan/phpstan/phpstan.phar/stubs/runtime/%s', $vendorPath, $stub);
// this is to handle phpstan's stubs got from phpstan-extracted instead of the .phar.
$path = sprintf('%s/phpstan/phpstan-extracted/stubs/runtime/%s', $vendorPath, $stub);
$isExists = file_exists($path);
if (! $isExists) {

View File

@ -61,9 +61,15 @@ final class DowngradePathsCommand extends Command
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/schema/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/finder/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/robot-loader/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/nette/bootstrap/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/ondram/ci-detector/src';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/finder';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console/Output/OutputInterface.php';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console/Output/TrimmedBufferOutput.php';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console/Logger/ConsoleLogger.php';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console/Style/SymfonyStyle.php';
$downgradePaths[] = 'vendor/phpstan/phpstan-extracted/vendor/symfony/console';
$downgradePaths[] = 'vendor/phpstan/phpstan-phpunit/src';
}
// bash format