[CI] add demo for build php 7.1 version (#4447)

* Renamed option to --exclude-path

* Exclude /**/tests/ by default

* Inverted order of downgrade

* Fixed verb

* Use sed to replace string

* Simplified message

* Use PHP version with "."

* Completed PHP versions to downgrade

* Execute Rector with --target-php-version

* Added quotes to array keys

* Allow to print command to output

* Execute script within workflow

* If rector fails, already exit 1

* Ignore PHP constraint

* Removed --dry-run and errors for testing

* Don't print command

* Run downgraded for ALL sets

* Include downgrade sets for testing

* Run all sets in a command each

* Added the target PHP version in each downgrade set

* Use a rector config file to pass exclude paths

* Exclude everything under /tests/

* Removed --dry-run

* Set unneeded transformations in false

* Exclude /ci/

* Exclude /compiler/

* Exclude DoctrineProvider

* Exclude classes for dependency-injection

* Exclude classes for http-kernel

* Exclude classes for symfony string

* Use cut instead of aws
For if the path has a space

* Calculate package execution order

* Downgrade packages on required order

* Consider the set to check package dependents

* Store packages_to_downgrade_by_set

* Store package_dependents["$package|$set"]

* Fixed converting from string to array

* Fixed converting string to array

* Fixed char

* Simplified counter

* Fixed string to array

* Fixed var

* Fixed getting dependents

* Fixed checking if dependent packages downgraded

* rector/rector has no dependents

* Simplified downgraded_packages

* Ignore dependent package on itself

* If circular dependencies, make the process fail

* Uncommented executing rector

* Exclude /stubs

* Calculate circular reference packages

* Break circular references

* Uncommented rector call

* Do downgrade ContainerBuilder

* Added expression-language as dep for PROD

* [ci-review] Generate Rector & Nodes documentation

* [ci-review] Apply coding standards

* [ci-review] Rector Rectify

* Obtain "rector/rector" from composer

* Removed commented code

* Don't do platform check for Composer v2

* Moved comment up

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* Must dump autload to remove platform_check.php

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* Copied file from master

* Use new convention (70000) for PHP versions (7.0)

* Fixed cs

* Fixed PHPStan

* Added "create-config" command - Initial commit

* [ci-review] Rector Rectify

* Moved rector config under custom folder

* Use predefined rector configs instead of injecting --set

* Created rector config files

* Use array of rector configs, even if only 1 is used

* Require once config file

* Fixed exclude paths

* Execute only last rector config (containing many sets)

* Exclude file that makes process fail

* Removed --dry-run

* Use existing option name

* Handle GROUP_RECTOR_CONFIGS in circular packages

* Changing PHP_VERSION_ID does not work, so commented rule

* Bug fixed => uncommented using rector

* Renamed NoParticularNodeRule to ForbiddenNodeRule

* [ci-review] Rector Rectify

* Fixed PHP version constants

* Added (failing) test

* Fixed issue for nullable scalars

* Can't run Rector with --set through CLI, removed

* Added (failing) test

* Fixed issue for __construct

* Fixed constant name

* Added (failing) test for self

* Added another (failing) test

* Fixed not adding "\" before "static", "self", etc

* [ci-review] Rector Rectify

* Skip downgrading CouchbaseBucketAdapter

* Renamed var

* Added (failing) test

* Fixed interface and abstract class issue

* [ci-review] Rector Rectify

* Fixed PHPStan error

* Create artifact of downgraded code

* Added missing spaces for args

* Use 4 spaces for consistency

* Ignore build folder in rector-php71.zip

* Switch to setup-php@v2

* Added (failing) test

* Issue is on calling method, not on constructor

* Implemented fix

* Renamed test

* Added further tests

* [ci-review] Rector Rectify

* Fixed PHPStan

* Fixed PHPStan

* Added (failing) test

* Fixed issue on new Class('foo', )

* Execute tests

* No need for quotes

* Made the artifact contain the folder, not a .zip

* Removed /compiler folder (it's been deleted?)

* Do upload the artifact as a .zip (too slow otherwise)

* Remove all tests, also from under vendor/

* Upgraded zip action version

* Change Composer's PHP requirement to 7.1

* Try exclude tests under vendor/

* Renamed artifact

* Try exclude tests under vendor/

* Updated test (to fail)

* If the float has no ".", add ".0" at the end

* Must remove deps before "composer require php"

* Replaced call to phpstan

* Cannot run PHPStan on 7.1, just run Rector

* Change Composer's PHP requirement to 7.1

* Remove DEV dependencies

* Require Symfony Polyfill libraries

* Rector without DEV needs phpstan.neon removed

* Run PHPStan

* Added paths to analyze

* Access PHPStan config from file

* Fixed relative paths

* Override the artifact with downgraded Composer too

* Uncommented scanDirectories

* Include tests/ in artifact

* Exclude */tests/*

* Ignore utils/phpstan-extensions

* PHPUnit is installed in DEV, can't use it in PROD

* "nette/application" is on DEV, may not exist on PROD

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* Improved comment after rectify

* Fixed previous messed-up merge

* Removed 1st slash

* Downgrade all dependencies together

* Replace the composer.json file

* Can't have more than 1 path to downgrade

* No need to change PHP requirement to 7.1 anymore

* Remove DEV dependencies before replacing composer.json

* Changed order of commands

* No need for --ignore-platform-req=php

* Add all Symfony polyfill libraries

* Require Symfony polyfill libraries earlier on

* Test removing `ignoreErrors` from PHPStan

* Remove ignored errors which do not apply

* Fixed the list of `excludes_analyse`

* Removed commented code

* Fixed PHPStan config

* Only analyze the target PHP version if GROUP_RECTOR_CONFIGS

* Simplified script: just analyze target PHP version

* Renamed downgrade sets

* Removed unneeded create-config command

* Removed call to deleted class

* Dropped ChangePhpVersionInPlatformCheckRector

* Must remove phpstan-for-rector.neon from PROD

* Do not execute --dry-run, it returns error

* Publish downgraded code to remote repository

* Removed commented code

* Standardized script code

* Initialize variables in script

* No need to initialize vars

* Remove the zip, do not copy to target repo

* Remove .git before deploying to target repo

* Copy files to rector-downgrade/

* Use branch "main"

* Copy also hidden files

* Remove docker publish image workflow

* Trigger own tests workflow

* Include "lowest"

* Run PHPStan instead of PHPUnit

* Run PHPStan in new temp directory

* Execute in same item

* "../" for --config doesn't work for PHPStan

* Added bare run test

* Added tests for PHP 7.2

* Added test

* Run with php

* Replaced namespace

* Added PHPUnit test for PHP 7.1

* Use PHP 7.1-compatible version of "doctrine/orm"

* Can't skip downgrading doctrine-annotation-generated

* Removed commented items

* Renamed test workflow

* Added comments on code

* Run all tests, not just 1

* Downgrade package from v3.1 to v3.0.7

* Run existing tests

* Revert tests

* [ci-review] Rector Rectify

Co-authored-by: Leonardo Losoviz <leo@getpop.org>
Co-authored-by: rector-bot <tomas@getrector.org>
This commit is contained in:
Tomas Votruba 2021-01-25 20:25:21 +01:00 committed by GitHub
parent 8d600ce412
commit abadc5473b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 1210 additions and 4 deletions

106
.github/workflows/build_php71.yaml vendored Normal file
View File

@ -0,0 +1,106 @@
name: Rector Run
on:
pull_request: null
push:
branches:
- master
jobs:
downgrade_php71:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
# The Symfony Polyfill libraries are needed
- run: composer require symfony/polyfill-php72 symfony/polyfill-php73 symfony/polyfill-php74 symfony/polyfill-php80 --no-install --no-update
# Execute the downgrade script
- run: ./.github/workflows/scripts/downgrade_packages.sh 7.1
# Upload the artifact so we can download and review the downgraded code
- run: mkdir build
- uses: montudor/action-zip@v0.1.1
with:
args: zip -X -r build/rector-php71.zip . -x *.git* .* "*/\.*" build** ci** stubs** tests** "**/tests**"
- uses: actions/upload-artifact@v2
with:
name: rector-downgraded-code
path: build/rector-php71.zip
# Run all the tests on PHP 7.4 (because JUnit needs PHP 7.3+),
# but using Rector downgraded to PHP 7.1
- run: vendor/bin/phpunit
# Avoid Composer v2 platform checks (composer.json requires PHP 7.3+, but below we are running 7.1)
- run: composer config platform-check false
# Regenerating the autoload files will remove vendor/composer/platform_check.php, otherwise executing bin/rector on 7.1 fails
- run: composer dumpautoload
# Remove DEV dependencies
- run: composer install --no-dev
# Replace the composer.json file
- run: cp ci/downgrade/composer.json ./composer.json
# Rector without DEV needs phpstan.neon removed
- run: rm phpstan.neon
- run: rm phpstan-for-rector.neon
# Override the artifact with downgraded Composer too
- run: rm build/rector-php71.zip
- uses: montudor/action-zip@v0.1.1
with:
args: zip -X -r build/rector-php71.zip . -x *.git* .* "*/\.*" build**
- uses: actions/upload-artifact@v2
with:
name: rector-downgraded-code
path: build/rector-php71.zip
# Switch to PHP 7.1 and run PHPStan to analyze the code,
# as to make sure no 7.2+ code was left behind (if there is, PHP will throw some error)
- uses: shivammathur/setup-php@v2
with:
php-version: 7.1
coverage: none
# Test the downgraded Rector by running the default set on its own src
- run: bin/rector process rules/downgrade-php70/src
# Run PHPStan to make sure no PHP 7.2+ code was left behind
- run: vendor/bin/phpstan analyse -c ci/downgrade/phpstan.neon --ansi
# If we reach here the downgrade works! Then, deploy it to its own repo
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none
# Copy all files for the target repo to rector-downgrade/
# Remove the artifact
- run: rm build/rector-php71.zip
- run: rm -R build
# Copy all files
- run: rsync -av * rector-downgrade --quiet
# Set-up own workflows for target repo
- run: cp -R ci/downgrade/target-repo/. rector-downgrade/
# publish it to remote repository
-
uses: symplify/github-action-monorepo-split@master
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
branch: 'main'
package-directory: 'rector-downgrade'
split-repository-organization: 'rectorphp'
split-repository-name: 'rector-php71'
user-name: "kaizen-ci"
user-email: "info@kaizen-ci.org"

View File

@ -0,0 +1,371 @@
#!/bin/bash
########################################################################
# This bash script downgrades the code to the selected PHP version
#
# Usage from within a GitHub workflow:
# .github/workflows/scripts/downgrade_packages.sh $target_php_version
# where $target_php_version is one of the following values:
# - 7.0
# - 7.1
# - 7.2
# - 7.3
# - 7.4
#
# Currently highest PHP version from which we can downgrade:
# - 8.0
#
# Eg: To downgrade to PHP 7.1, execute:
# .github/workflows/scripts/downgrade_packages.sh 7.1
########################################################################
# show errors
set -e
########################################################################
# Variables to modify when new PHP versions are released
# ----------------------------------------------------------------------
supported_target_php_versions=(7.0 7.1 7.2 7.3 7.4)
# Rector configs carry the previous downgrade sets starting from php80
# (eg: latest-to-php73 has downgrade sets php80 and php74)
# so even though we're storing all the stages, only the last item must be executed
# (only latest-to-php73, no need for latest-to-php74) or a same downgrade will be executed more than once
# This logic is a bit redundant, but it enables to execute several config files on each package,
# eg: defining the set to execute using `--set` in the CLI (not supported anymore)
GROUP_RECTOR_CONFIGS=true
# Execute a single call to Rector for all dependencies together?
DOWNGRADE_DEPENDENCIES_TOGETHER=true
# If grouping rector configs, analyze if the libraries support
# only the target PHP version
# Otherwise, analyze PHP support starting from the latest PHP version
# (currently 8.0) to the target one, so different libraries can be
# downgraded only for their needed versions, not all of them
declare -A downgrade_php_whynots
declare -A downgrade_php_rectorconfigs
if [ -n "$GROUP_RECTOR_CONFIGS" ]; then
downgrade_php_whynots=( \
["7.0"]="7.0.*" \
["7.1"]="7.1.*" \
["7.2"]="7.2.*" \
["7.3"]="7.3.*" \
["7.4"]="7.4.*" \
)
downgrade_php_rectorconfigs=( \
["7.0"]="latest-to-php70" \
["7.1"]="latest-to-php71" \
["7.2"]="latest-to-php72" \
["7.3"]="latest-to-php73" \
["7.4"]="latest-to-php74" \
)
else
downgrade_php_whynots=( \
["7.0"]="7.4.* 7.3.* 7.2.* 7.1.* 7.0.*" \
["7.1"]="7.4.* 7.3.* 7.2.* 7.1.*" \
["7.2"]="7.4.* 7.3.* 7.2.*" \
["7.3"]="7.4.* 7.3.*" \
["7.4"]="7.4.*" \
)
downgrade_php_rectorconfigs=( \
["7.0"]="php80-to-74 php74-to-73 php73-to-72 php72-to-71 php71-to-70" \
["7.1"]="php80-to-74 php74-to-73 php73-to-72 php72-to-71" \
["7.2"]="php80-to-74 php74-to-73 php73-to-72" \
["7.3"]="php80-to-74 php74-to-73" \
["7.4"]="php80-to-74" \
)
fi
########################################################################
# Helper functions
# ----------------------------------------------------------------------
# Failure helper function (https://stackoverflow.com/a/24597941)
function fail {
printf '%s\n' "$1" >&2 ## Send message to stderr. Exclude >&2 if you don't want it that way.
exit "${2-1}" ## Return a code specified by $2 or 1 by default.
}
# Print array helpers (https://stackoverflow.com/a/17841619)
function join_by { local d=$1; shift; local f=$1; shift; printf %s "$f" "${@/#/$d}"; }
function note {
MESSAGE=$1;
printf "\n";
echo "[NOTE] $MESSAGE";
printf "\n";
}
########################################################################
target_php_version=$1
if [ -z "$target_php_version" ]; then
versions=$(join_by ", " ${supported_target_php_versions[@]})
fail "Please provide to which PHP version to downgrade to ($versions) as first argument to the bash script"
fi
# Check the version is supported
if [[ ! " ${supported_target_php_versions[@]} " =~ " ${target_php_version} " ]]; then
versions=$(join_by ", " ${supported_target_php_versions[@]})
fail "Version $target_php_version is not supported for downgrading. Supported versions: $versions"
fi
target_downgrade_php_whynots=($(echo ${downgrade_php_whynots[$target_php_version]} | tr " " "\n"))
target_downgrade_php_rectorconfigs=($(echo ${downgrade_php_rectorconfigs[$target_php_version]} | tr " " "\n"))
packages_to_downgrade=()
rectorconfigs_to_downgrade=()
declare -A package_paths
declare -A packages_by_rectorconfig
# Switch to production
composer install --no-dev --no-progress --ansi
rootPackage=$(composer info -s -N)
numberTargetPHPVersions=${#target_downgrade_php_whynots[@]}
counter=1
while [ $counter -le $numberTargetPHPVersions ]
do
pos=$(( $counter - 1 ))
whynot=${target_downgrade_php_whynots[$pos]}
rector_config=${target_downgrade_php_rectorconfigs[$pos]}
note "Analyzing which packages do not support PHP version $whynot"
# Obtain the list of packages for production that need a higher version that the input one.
# Those must be downgraded
PACKAGES=$(composer why-not php $whynot --no-interaction | grep -o "\S*\/\S*")
if [ -n "$PACKAGES" ]; then
for package in $PACKAGES
do
note "Enqueueing rector_config $rector_config on package $package"
# Composer also analyzes the root project but its path is directly the root folder
if [ $package = "$rootPackage" ]
then
path=$(pwd)
else
# Obtain the package's path from Composer
# Format is "package path", so extract everything after the 1st word with cut to obtain the path
path=$(composer info $package --path | cut -d' ' -f2-)
fi
packages_to_downgrade+=($package)
rectorconfigs_to_downgrade+=($rector_config)
package_paths[$package]=$path
packages_by_rectorconfig[$rector_config]=$(echo "${packages_by_rectorconfig[$rector_config]} ${package}")
done
else
note "No packages to downgrade"
fi
((counter++))
done
# Switch to dev again
composer install --no-progress --ansi
# Make sure that the number of packages, paths and sets is the same
# otherwise something went wrong
numberPackages=${#packages_to_downgrade[@]}
numberRectorConfigs=${#rectorconfigs_to_downgrade[@]}
if [ ! $numberRectorConfigs -eq $numberPackages ]; then
fail "Number of Rector configs ($numberRectorConfigs) and number of packages ($numberPackages) should not be different"
fi
# Execute a single call to Rector for all dependencies together:
# If grouping the PHP-version downgrades together, and downgrading the packages together
if [ -n "$GROUP_RECTOR_CONFIGS" ] && [ -n "$DOWNGRADE_DEPENDENCIES_TOGETHER" ]
then
# The config is the last element on the array
target_rector_configs=($(echo ${downgrade_php_rectorconfigs[$target_php_version]} | tr " " "\n"))
numberElems=${#target_rector_configs[@]}
lastPos=$(( $numberElems - 1 ))
rector_config=${target_rector_configs[$lastPos]}
# Collect the list of all dependencies and their paths
dependency_packages=()
dependency_package_paths=()
# Iterate all the packages, and obtain their paths
for package_to_downgrade in "${packages_to_downgrade[@]}"; do
path_to_downgrade=${package_paths[$package_to_downgrade]}
if [ $package_to_downgrade != "$rootPackage" ]
then
#Check it's not been added yet (eg: from needing downgrade for several PHP versions)
if [[ " ${dependency_packages[@]} " =~ " ${package_to_downgrade} " ]]; then
continue;
fi
dependency_packages+=($package_to_downgrade)
dependency_package_path=${package_paths[$package_to_downgrade]}
dependency_package_paths+=($dependency_package_path)
fi
done
# Execute the downgrade
# Downgrade Rector first
path_to_downgrade=${package_paths[$rootPackage]}
config=ci/downgrade/rector-downgrade-rector
config="${config}-${rector_config}.php"
note "Running rector_config ${rector_config} for main package ${rootPackage} on path(s) ${path_to_downgrade}"
bin/rector process $path_to_downgrade --config=$config --ansi
#Downgrade all the dependencies then
packages_to_downgrade=$(join_by " " ${dependency_packages[@]})
paths_to_downgrade=$(join_by " " ${dependency_package_paths[@]})
config=ci/downgrade/rector-downgrade-dependency
config="${config}-${rector_config}.php"
note "Running rector_config ${rector_config} for dependency packages ${packages_to_downgrade} on paths ${paths_to_downgrade}"
bin/rector process $paths_to_downgrade --config=$config --ansi
# Success
exit 0
fi
# We must downgrade packages in the strict dependency order,
# such as sebastian/diff => symfony/event-dispatcher-contracts => psr/event-dispatcher,
# or otherwise there may be PHP error from inconsistencies (such as from a modified interface)
# To do this, have a double loop to downgrade packages,
# asking if all the "ancestors" for the package have already been downgraded,
# or let it keep iterating until next loop
# Calculate all the dependents for all packages,
# including only packages to be downgraded
note "Calculating package execution order"
declare -A package_dependents
counter=1
while [ $counter -le $numberPackages ]
do
pos=$(( $counter - 1 ))
package_to_downgrade=${packages_to_downgrade[$pos]}
rector_config=${rectorconfigs_to_downgrade[$pos]}
IFS=' ' read -r -a packages_to_downgrade_by_rectorconfig <<< "${packages_by_rectorconfig[$rector_config]}"
dependents_to_downgrade=()
# Obtain recursively the list of dependents, keep the first word only,
# (which is the package name), and remove duplicates
dependentsAsString=$(composer why "$package_to_downgrade" -r | cut -d' ' -f1 | awk '!a[$0]++' | tr "\n" " ")
IFS=' ' read -r -a dependents <<< "$dependentsAsString"
for dependent in "${dependents[@]}"; do
# A package could provide itself in why (as when using "replaces"). Ignore them
if [ $dependent = $package_to_downgrade ]; then
continue
fi
# Only add the ones which must themselves be downgraded for that same rector config
if [[ ! " ${packages_to_downgrade_by_rectorconfig[@]} " =~ " ${dependent} " ]]; then
continue;
fi
dependents_to_downgrade+=($dependent)
done
# The dependents are identified per package and rector_config, because a same dependency
# downgraded for 2 rector_config might have dependencies downgraded for one rector_config and not the other
key="${package_to_downgrade}_${rector_config}"
package_dependents[$key]=$(echo "${dependents_to_downgrade[@]}")
note "Dependents for package ${package_to_downgrade} and rector_config ${rector_config}: ${dependents_to_downgrade[@]}"
((counter++))
done
# In case of circular dependencies (eg: package1 requires package2
# and package2 requires package1), the process will fail
# hasNonDowngradedDependents=()
declare -A circular_reference_packages_by_rector_config
note "Executing Rector to downgrade $numberDowngradedPackages packages"
downgraded_packages=()
numberDowngradedPackages=1
previousNumberDowngradedPackages=1
until [ $numberDowngradedPackages -gt $numberPackages ]
do
counter=1
while [ $counter -le $numberPackages ]
do
pos=$(( $counter - 1 ))
((counter++))
package_to_downgrade=${packages_to_downgrade[$pos]}
rector_config=${rectorconfigs_to_downgrade[$pos]}
key="${package_to_downgrade}_${rector_config}"
# Check if this package has already been downgraded on a previous iteration
if [[ " ${downgraded_packages[@]} " =~ " ${key} " ]]; then
continue
fi
# Check if all dependents have already been downgraded. Otherwise, keep iterating
hasNonDowngradedDependent=""
IFS=' ' read -r -a dependents <<< "${package_dependents[$key]}"
for dependent in "${dependents[@]}"; do
dependentKey="${dependent}_${rector_config}"
if [[ ! " ${downgraded_packages[@]} " =~ " ${dependentKey} " ]]; then
hasNonDowngradedDependent="true"
circular_reference_packages_by_rector_config[${rector_config}]=$(echo "${circular_reference_packages_by_rector_config[$rector_config]} ${dependent}")
fi
done
if [ -n "${hasNonDowngradedDependent}" ]; then
continue
fi
# Mark this package as downgraded
downgraded_packages+=($key)
((numberDowngradedPackages++))
path_to_downgrade=${package_paths[$package_to_downgrade]}
if [ $package_to_downgrade = "$rootPackage" ]
then
config=ci/downgrade/rector-downgrade-rector
else
config=ci/downgrade/rector-downgrade-dependency
fi
# Attach the specific rector config as a file suffix
config="${config}-${rector_config}.php"
note "Running rector_config ${rector_config} for package ${package_to_downgrade} on path(s) ${path_to_downgrade}"
# Execute the downgrade
bin/rector process $path_to_downgrade --config=$config --ansi
# If Rector fails, already exit
if [ "$?" -gt 0 ]; then
fail "Rector downgrade failed on rector_config ${rector_config} for package ${package_to_downgrade}"
fi
done
# If no new package was downgraded, it must be because of circular dependencies
if [ $numberDowngradedPackages -eq $previousNumberDowngradedPackages ]
then
if [ ${#circular_reference_packages_by_rector_config[@]} -eq 0 ]; then
fail "For some unknown reason, not all packages have been downgraded"
fi
# Resolve all involved packages all together
note "Resolving circular reference packages all together"
for rector_config in "${!circular_reference_packages_by_rector_config[@]}";
do
circular_packages_to_downgrade=($(echo "${circular_reference_packages_by_rector_config[$rector_config]}" | tr ' ' '\n' | sort -u))
circular_packages_to_downgrade_for_rectorconfig=()
circular_paths_to_downgrade_for_rectorconfig=()
for package_to_downgrade in "${circular_packages_to_downgrade[@]}";
do
# Mark this package as downgraded
key="${package_to_downgrade}_${rector_config}"
downgraded_packages+=($key)
((numberDowngradedPackages++))
# This package does need downgrading (eg: it had not been already downgraded via GROUP_RECTOR_CONFIGS)
circular_packages_to_downgrade_for_rectorconfig+=($package_to_downgrade)
# Obtain the path
circular_paths_to_downgrade_for_rectorconfig+=(${package_paths[$package_to_downgrade]})
done
# Check that possibly all packages had already been downgraded via GROUP_RECTOR_CONFIGS
if [ ${#circular_packages_to_downgrade_for_rectorconfig[@]} -gt 0 ]; then
paths_to_downgrade=$(join_by " " ${circular_paths_to_downgrade_for_rectorconfig[@]})
note "Running rector_config ${rector_config} for packages ${circular_packages_to_downgrade_for_rectorconfig[@]}"
config="ci/downgrade/rector-downgrade-dependency-${rector_config}.php"
bin/rector process $paths_to_downgrade --config=$config --ansi
# If Rector fails, already exit
if [ "$?" -gt 0 ]; then
fail "Rector downgrade failed on rector_config ${rector_config} for package ${package_to_downgrade}"
fi
else
note "All circular packages had already been downgraded: ${circular_packages_to_downgrade[@]}"
fi
done
fi
circular_reference_packages_by_rector_config=()
previousNumberDowngradedPackages=$numberDowngradedPackages
done

View File

@ -0,0 +1,14 @@
{
"name": "rector/rector-php71",
"description": "PHP 7.1-compatible version of rector/rector package",
"license": "MIT",
"require": {
"php": "^7.1"
},
"bin": [
"bin/rector"
],
"replace": {
"rector/rector": "self.version"
}
}

View File

@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/**
* Configuration consts for the different rector.php config files
*/
final class DowngradeRectorConfig
{
/**
* Exclude paths when downgrading a dependency
*/
public const DEPENDENCY_EXCLUDE_PATHS = [
'*/tests/*',
// Individual classes that can be excluded because
// they are not used by Rector, and they use classes
// loaded with "require-dev" so it'd throw an error
__DIR__ . '/../../vendor/symfony/cache/DoctrineProvider.php',
__DIR__ . '/../../vendor/symfony/cache/Messenger/EarlyExpirationHandler.php',
__DIR__ . '/../../vendor/symfony/http-kernel/HttpKernelBrowser.php',
__DIR__ . '/../../vendor/symfony/string/Slugger/AsciiSlugger.php',
// This class has an issue for PHP 7.1:
// https://github.com/rectorphp/rector/issues/4816#issuecomment-743209526
// It doesn't happen often, and Rector doesn't use it, so then
// we simply skip downgrading this class
__DIR__ . '/../../vendor/symfony/cache/Adapter/CouchbaseBucketAdapter.php',
];
/**
* Exclude paths when downgrading the Rector source code
*/
public const RECTOR_EXCLUDE_PATHS = [
'*/tests/*',
__DIR__ . '/../../packages/rector-generator/templates/*',
__DIR__ . '/../../vendor/*',
__DIR__ . '/../../ci/*',
__DIR__ . '/../../stubs/*',
];
}

37
ci/downgrade/phpstan.neon Normal file
View File

@ -0,0 +1,37 @@
parameters:
level: 0
paths:
- ../../src
- ../../rules
- ../../packages
- ../../utils
reportUnmatchedIgnoredErrors: false
scanDirectories:
- ../../stubs
excludes_analyse:
# List of all excluded elements for Rector and its dependencies
# from ci/downgrade/configuration.php
# Rector:
- */tests/*
- ../../ci/*
# - ../../stubs/* # Even if not downgraded, they are needed to run PHPStan
- ../../packages/rector-generator/templates/*
- ../../packages/doctrine-annotation-generated/src/*
# Dependencies:
- ../../vendor/symfony/cache/DoctrineProvider.php
- ../../vendor/symfony/cache/Messenger/EarlyExpirationHandler.php
- ../../vendor/symfony/http-kernel/HttpKernelBrowser.php
- ../../vendor/symfony/string/Slugger/AsciiSlugger.php
- ../../vendor/symfony/cache/Adapter/CouchbaseBucketAdapter.php
# broken in PHPStan https://github.com/rectorphp/rector/runs/1305002460#step:5:56
- ../../utils/phpstan-extensions/*
- ../../packages/testing/src/PHPUnit/*.php
ignoreErrors:
# trait in trait call
- '#Call to an undefined method Rector\\PostRector\\Rector\\AbstractPostRector\:\:isObjectType\(\)#'

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
DowngradeSetList::PHP_71,
]);
};

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
]);
};

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
]);
};

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_71,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_72,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_73,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_74,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::DEPENDENCY_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
]);
};

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
DowngradeSetList::PHP_71,
]);
};

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
DowngradeSetList::PHP_72,
]);
};

View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
DowngradeSetList::PHP_73,
]);
};

View File

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
DowngradeSetList::PHP_74,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_71,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_72,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_73,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_74,
]);
};

View File

@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\DowngradeSetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
require_once __DIR__ . '/configuration.php';
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SKIP, DowngradeRectorConfig::RECTOR_EXCLUDE_PATHS);
$parameters->set(Option::SETS, [
DowngradeSetList::PHP_80,
]);
};

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(FinalizeClassesWithoutChildrenRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTOLOAD_PATHS, [
__DIR__ . '/tests/Finalize/Fixture/Source'
]);
};

View File

@ -0,0 +1,23 @@
name: Bare Run
on: [pull_request, push]
jobs:
bare_run:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version: ['7.1', '7.2']
steps:
- uses: actions/checkout@v2
-
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
coverage: none
- run: php bin/rector --ansi

View File

@ -0,0 +1,28 @@
name: PHPStan
on: [pull_request, push]
jobs:
along_phpstan:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version: ['7.1', '7.2']
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 temp && cd temp
composer require phpstan/phpstan --dev --ansi --no-interaction
cd ..
temp/vendor/bin/phpstan analyse -c ci/downgrade/phpstan.neon --ansi

View File

@ -0,0 +1,39 @@
name: Tests
on: [pull_request, push]
jobs:
finalize_classes:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php_version: ['7.1', '7.2']
name: "PHP ${{ matrix.php_version }}"
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
coverage: none
# Use library versions compatible with PHP 7.1
- run: |
mkdir temp && cd temp
composer require "doctrine/orm:~2.7.5" --ansi --no-interaction
composer require "phpunit/phpunit:~7.5" --dev --ansi --no-interaction
# Apply Rector on a few sources
- run: |
cd temp
../bin/rector process ../ci/downgrade/tests/Finalize/Fixture/Source --config ../ci/downgrade/rector-test-downgrade.php --ansi
# Validate the results are the expected ones
- run: |
cd temp
vendor/bin/phpunit ../ci/downgrade/tests/

View File

@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace Rector\RectorPhp71\Tests\Finalize;
use PHPUnit\Framework\TestCase;
final class FinalizeTest extends TestCase
{
/**
* @dataProvider getFiles
*/
public function testRectoredFileEquals($rectoredFile, $expectedFile): void
{
$this->assertFileEquals($rectoredFile, $expectedFile);
}
public function getFiles(): array
{
$files = glob(__DIR__ . '/Fixture/Source/*.php');
return array_map(
function ($file) {
return [
$file,
__DIR__ . '/Fixture/Expected/' . basename($file),
];
},
$files
);
}
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Rector\RectorPhp71\Tests\Finalize;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class SkipSomeEntity
{
}

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Rector\RectorPhp71\Tests\Finalize;
final class SomeClassWithoutChildren
{
}

View File

@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Rector\RectorPhp71\Tests\Finalize;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class SkipSomeEntity
{
}

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace Rector\RectorPhp71\Tests\Finalize;
class SomeClassWithoutChildren
{
}

View File

@ -38,6 +38,7 @@
"sebastian/diff": "^4.0",
"symfony/cache": "^4.4.8|^5.1",
"symfony/console": "^4.4.8|^5.1",
"symfony/expression-language": "^4.4|^5.1",
"symfony/dependency-injection": "^5.1",
"symfony/finder": "^4.4.8|^5.1",
"symfony/http-kernel": "^4.4.8|^5.1",
@ -56,7 +57,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17.3",
"nette/application": "^3.0",
"nette/application": "^3.0.7",
"nette/di": "^3.0",
"nette/forms": "^3.0",
"ocramius/package-versions": "^1.9",

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp71\Rector\Array_\SymmetricArrayDestructuringToListRector;
use Rector\DowngradePhp71\Rector\ClassConst\DowngradeClassConstantVisibilityRector;
use Rector\DowngradePhp71\Rector\FunctionLike\DowngradeNullableTypeParamDeclarationRector;
@ -16,6 +18,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(DowngradeNullableTypeParamDeclarationRector::class);
$services->set(DowngradeNullableTypeReturnDeclarationRector::class);
$services->set(DowngradeVoidTypeReturnDeclarationRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_70);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$services->set(DowngradeClassConstantVisibilityRector::class);
$services->set(DowngradePipeToMultiCatchExceptionRector::class);
$services->set(SymmetricArrayDestructuringToListRector::class);

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector;
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeParamObjectTypeDeclarationRector;
use Rector\DowngradePhp72\Rector\FunctionLike\DowngradeReturnObjectTypeDeclarationRector;
@ -11,5 +13,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(DowngradeParamObjectTypeDeclarationRector::class);
$services->set(DowngradeReturnObjectTypeDeclarationRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_71);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$services->set(DowngradeParameterTypeWideningRector::class);
};

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp73\Rector\FuncCall\DowngradeTrailingCommasInFunctionCallsRector;
use Rector\DowngradePhp73\Rector\FuncCall\SetCookieOptionsArrayToArgumentsRector;
use Rector\DowngradePhp73\Rector\List_\DowngradeListReferenceAssignmentRector;
@ -12,6 +14,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(DowngradeFlexibleHeredocSyntaxRector::class);
$services->set(DowngradeListReferenceAssignmentRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_72);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$services->set(DowngradeTrailingCommasInFunctionCallsRector::class);
$services->set(SetCookieOptionsArrayToArgumentsRector::class);
};

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp74\Rector\Array_\DowngradeArraySpreadRector;
use Rector\DowngradePhp74\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector;
use Rector\DowngradePhp74\Rector\ClassMethod\DowngradeContravariantArgumentTypeRector;
@ -26,6 +28,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(DowngradeStripTagsCallWithArrayRector::class);
$services->set(DowngradeArraySpreadRector::class);
$services->set(DowngradeArrayMergeCallWithoutArgumentsRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$services->set(DowngradeFreadFwriteFalsyToNegationRector::class);
$services->set(DowngradeReturnSelfTypeDeclarationRector::class);
};

View File

@ -2,6 +2,8 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DowngradePhp80\Rector\Catch_\DowngradeNonCapturingCatchesRector;
use Rector\DowngradePhp80\Rector\Class_\DowngradePropertyPromotionRector;
use Rector\DowngradePhp80\Rector\ClassConstFetch\DowngradeClassOnObjectToGetClassRector;
@ -24,6 +26,15 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(DowngradeParamMixedTypeDeclarationRector::class);
$services->set(DowngradeReturnMixedTypeDeclarationRector::class);
$services->set(DowngradeReturnStaticTypeDeclarationRector::class);
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
$services->set(DowngradePropertyPromotionRector::class);
$services->set(DowngradeNonCapturingCatchesRector::class);
$services->set(DowngradeMatchToSwitchRector::class);

View File

@ -138,7 +138,7 @@ CODE_SAMPLE
// Obtain the list of the ancestors classes and implemented interfaces
// with a different signature
$ancestorAndInterfaceClassNames = array_merge(
$ancestorAndInterfaces = array_merge(
$this->getClassesWithDifferentSignature($classReflection, $methodName, $paramName),
$this->getInterfacesWithDifferentSignature($classReflection, $methodName, $paramName)
);
@ -146,8 +146,7 @@ CODE_SAMPLE
// Remove the types in:
// - all ancestors + their descendant classes
// - all implemented interfaces + their implementing classes
foreach ($ancestorAndInterfaceClassNames as $ancestorClassOrInterface) {
/** @var string $parentClassName */
foreach ($ancestorAndInterfaces as $ancestorClassOrInterface) {
$parentClassName = $ancestorClassOrInterface->getAttribute(AttributeKey::CLASS_NAME);
$classMethod = $this->nodeRepository->findClassMethod($parentClassName, $methodName);
/**