Skip to content

Commit

Permalink
Upgrade to nikic/php-parser v5
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed May 10, 2024
1 parent bc6fe0b commit 4b8fe1c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## UNRELEASED (0.5.0)

**Compatibility**

- Added compatibility with `nikic/php-parser` `5.x`
- Removed compatibility with `nikic/php-parser` `4.x`

## [0.4.0](https://github.com/brick/varexporter/releases/tag/0.4.0) - 2023-09-01

Minimum PHP version is now `7.4`. No breaking changes.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"nikic/php-parser": "^4.0"
"nikic/php-parser": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
3 changes: 2 additions & 1 deletion src/Internal/ObjectExporter/ClosureExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PhpParser\PhpVersion;
use ReflectionFunction;

/**
Expand Down Expand Up @@ -67,7 +68,7 @@ public function export(object $object, \ReflectionObject $reflectionObject, arra
private function getParser()
{
if ($this->parser === null) {
$this->parser = (new ParserFactory)->create(ParserFactory::ONLY_PHP7);
$this->parser = (new ParserFactory)->createForVersion(PhpVersion::fromComponents(7, 4));
}

return $this->parser;
Expand Down
18 changes: 9 additions & 9 deletions tests/ExportClosureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testExportNestedComplexClosure(): void
[
(object) [
'callback' => function () {
return function (\Brick\VarExporter\Tests\Classes\PublicPropertiesOnly $a, int $b, string &$c, string ...$d) : ?string {
return function (\Brick\VarExporter\Tests\Classes\PublicPropertiesOnly $a, int $b, string &$c, string ...$d): ?string {
$a->foo += $b;
$c = $a->bar;
$a->bar = implode('', $d);
Expand Down Expand Up @@ -91,8 +91,8 @@ public function testExportNamespacedCode(): void
};

$expected = <<<'PHP'
function (\Brick\VarExporter\Tests\Classes\SetState $a) : array {
return ['callback' => function (\Brick\VarExporter\Tests\Classes\SetState $a) : \Brick\VarExporter\Tests\Classes\NoProperties {
function (\Brick\VarExporter\Tests\Classes\SetState $a): array {
return ['callback' => function (\Brick\VarExporter\Tests\Classes\SetState $a): \Brick\VarExporter\Tests\Classes\NoProperties {
strlen(PHP_VERSION);
\Brick\VarExporter\Dummy\Functions\imported_function(\Brick\VarExporter\Dummy\Constants\IMPORTED_CONSTANT);
\Brick\VarExporter\Dummy\Functions\explicitly_namespaced_function(\Brick\VarExporter\Dummy\Constants\EXPLICITLY_NAMESPACED_CONSTANT);
Expand Down Expand Up @@ -128,13 +128,13 @@ public function testExportClosureWithStringsContainingLikeBreaks(): void
$a = 'Hello,
World!';
$b = <<<TXT
Hello,
world!
TXT;
Hello,
world!
TXT;
$c = <<<'TXT'
Hello,
world!
TXT;
Hello,
world!
TXT;
return $a . $b . $c;
};

Expand Down
12 changes: 6 additions & 6 deletions tests/VarExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,13 @@ public function foo()
$a = 'Hello,
World!';
$b = <<<TXT
Hello,
world!
TXT;
Hello,
world!
TXT;
$c = <<<'TXT'
Hello,
world!
TXT;
Hello,
world!
TXT;
return $a . $b . $c;
};
}
Expand Down

0 comments on commit 4b8fe1c

Please sign in to comment.