Skip to content

Commit

Permalink
fix: Configure the printer PHP version to 7.2 by default (#1049)
Browse files Browse the repository at this point in the history
See the discussion in nikic/PHP-Parser#1007.

This should fix sebastianbergmann/phpunit#5855 although this may result in more ugly code formatting than desired. For this reason the default printer version is 7.2 rather than 5.3 as it would make the code too otherwise.
  • Loading branch information
theofidry committed Jun 16, 2024
1 parent 226ba7d commit 41eff3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 12 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,19 @@ then a random prefix will be automatically generated.

### PHP Version

The PHP version provided is used to configure the underlying [PHP-Parser] Parser and Printer. This will not affect
the PHP internal symbols used by PHP-Scoper but may affect what code can be parsed and how the code will be printed.
The PHP version provided is used to configure the underlying [PHP-Parser] Parser and Printer.

If `null` or `''` (empty string) is given, then the host version will be used, i.e. executing it with PHP 8.4 will
result in PHP 8.4 being used as the PHP version.
The version used by the Parser will affect what code it can understand, e.g. if it is configured in PHP 8.2 it will not
understand a PHP 8.3 construct (e.g. typed class constants). However, what symbols are interpreted as internal will
remain unchanged. The function `json_validate()` will be considered as internal even if the parser is configured with
PHP 8.2.

The printer version affects the code style. For example nowdocs and heredocs will be indented if the printer's PHP
version is higher than 7.4 but will be formated without indent otherwise.

If `null` or `''` (empty string) is given, then the host version will be used for the parser and 7.2 will be used for
the printer. This allows PHP-Scoper to a PHP 7.2 compatible codebase without breaking its compatibility although the
host version is a newer version.


### Output directory
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,3 @@ parameters:
# Fixed in https://github.com/nikic/PHP-Parser/pull/1003
- message: '#Standard constructor expects array#'
path: 'src/Container.php'
- message: '#Standard constructor expects array#'
path: 'src/PhpParser/Printer/StandardPrinterFactory.php'
2 changes: 1 addition & 1 deletion src/PhpParser/Printer/StandardPrinterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function createPrinter(?PhpVersion $phpVersion = null): Printer
{
return new StandardPrinter(
new Standard([
'phpVersion' => $phpVersion,
'phpVersion' => $phpVersion ?? PhpVersion::fromComponents(7, 2),
]),
);
}
Expand Down

0 comments on commit 41eff3d

Please sign in to comment.