Skip to content

Commit 41eff3d

Browse files
authored
fix: Configure the printer PHP version to 7.2 by default (#1049)
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.
1 parent 226ba7d commit 41eff3d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

docs/configuration.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ then a random prefix will be automatically generated.
6060

6161
### PHP Version
6262

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

66-
If `null` or `''` (empty string) is given, then the host version will be used, i.e. executing it with PHP 8.4 will
67-
result in PHP 8.4 being used as the PHP version.
65+
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
66+
understand a PHP 8.3 construct (e.g. typed class constants). However, what symbols are interpreted as internal will
67+
remain unchanged. The function `json_validate()` will be considered as internal even if the parser is configured with
68+
PHP 8.2.
69+
70+
The printer version affects the code style. For example nowdocs and heredocs will be indented if the printer's PHP
71+
version is higher than 7.4 but will be formated without indent otherwise.
72+
73+
If `null` or `''` (empty string) is given, then the host version will be used for the parser and 7.2 will be used for
74+
the printer. This allows PHP-Scoper to a PHP 7.2 compatible codebase without breaking its compatibility although the
75+
host version is a newer version.
6876

6977

7078
### Output directory

phpstan.neon.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,3 @@ parameters:
6161
# Fixed in https://github.com/nikic/PHP-Parser/pull/1003
6262
- message: '#Standard constructor expects array#'
6363
path: 'src/Container.php'
64-
- message: '#Standard constructor expects array#'
65-
path: 'src/PhpParser/Printer/StandardPrinterFactory.php'

src/PhpParser/Printer/StandardPrinterFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function createPrinter(?PhpVersion $phpVersion = null): Printer
2323
{
2424
return new StandardPrinter(
2525
new Standard([
26-
'phpVersion' => $phpVersion,
26+
'phpVersion' => $phpVersion ?? PhpVersion::fromComponents(7, 2),
2727
]),
2828
);
2929
}

0 commit comments

Comments
 (0)