Qodana 2023.2 Help

PHP version migration

If you need to see how migration from one PHP version to another will affect your code quality, you can use the php-migration Qodana scenario. If you run this scenario, you will be able to see the codebase problems that will arise after you upgrade to a newer PHP version.

This feature is supported by the Qodana for PHP linter and available under the Ultimate and Ultimate Plus licenses and their trial versions.

PHP language migration

You can configure this scenario either in the qodana.yaml file or invoke it using the CLI.

script: name: php-migration parameters: fromLevel: <old-php-version> toLevel: <upgraded-php-version>

This snippet specifies the php-migration scenario using the name parameter. The fromLevel and toLevel parameters denote the old and upgraded PHP versions respectively.

This is the example of the qodana.yaml configuration:

script: name: php-migration parameters: fromLevel: 7.1 toLevel: 8.0

Here, you have two options for running this feature:

qodana scan \ --script php-migration:<old-php-version>-to-<upgraded-php-version>
docker run \ -v <source-directory>/:/data/project/ \ jetbrains/qodana-<linter> \ --script php-migration:<old-php-version>-to-<upgraded-php-version>

This snippet specifies the php-migration scenario for the --script option followed by the colon : character, and PHP versions separated by the -to- character combination.

This is the example of the CLI command:

qodana scan \ --script php-migration:7.1-to-8.0
docker run \ -v <source-directory>/:/data/project/ \ jetbrains/qodana-<linter> \ --script php-migration:7.1-to-8.0

Example

To show how the language migration feature works, the following PHP code snippet will be inspected:

<?php function f($a) { switch ($a) { case 1: return 1; case 2: return 2; default: return 3; } }

If you run Qodana with version 7.1 of the PHP runtime, the report will contain the following problems:

Analysis results: 2 problems detected Grouping problems by severity: Info: 2 Name Severity Count problems Missing return type declaration Info 1 Unused declaration Info 1

Running Qodana with version 8.0 of the PHP runtime will produce the following output:

Analysis results: 3 problems detected Grouping problems by severity: Info: 3 Name Severity Count problems Missing return type declaration Info 1 Unused declaration Info 1 'switch' can be replaced with 'match' expression Info 1

Running Qodana with the migration feature enabled will produce the following report:

Analysis results: 1 problems detected Grouping problems by severity: Info: 1 Name Severity Count problems 'switch' can be replaced with 'match' expression Info 1

As you can see, the migration report contains only the problem contained in the version 8.0 report and missing from the version 7.1 report.

Last modified: 24 July 2023