Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ 7.3, 7.4, 8.0, 8.1, 8.2 ]
php: [ 8.0, 8.1, 8.2, 8.3, 8.4 ]
experimental: [ false ]
include:
- php: 8.1
- php: 8.2
analysis: true
- php: 8.3
experimental: true
- php: 8.4
experimental: true

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
]
},
"require": {
"php": "^7.3 || ^8.0",
"nikic/php-parser": "^4.4"
"php": "^8.0",
"nikic/php-parser": "^5.3"
},
"require-dev": {
"phpstan/phpstan": "^1.12",
Expand Down
26 changes: 3 additions & 23 deletions src/CodeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\Parser;
use PhpParser\Parser\Php7;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
use RuntimeException;

Expand All @@ -41,11 +42,6 @@ class CodeConverter
*/
protected $parser;

/**
* @var Lexer The PHP Lexer.
*/
protected $lexer;

/**
* @var NodeTraverser The PHP Node Traverser.
*/
Expand All @@ -62,23 +58,19 @@ class CodeConverter
protected $nodeFinder;

/**
* @param Lexer|null $lexer The PHP Lexer.
* @param Parser|null $parser The PHP Parser.
* @param NodeTraverser|null $traverser The PHP Node Traverser - make sure that the traverser has a CloningVisitor
* and a NameResolver visitor.
* @param Standard|null $printer The PHP Printer.
* @param NodeFinder|null $nodeFinder The PHP Node Finder.
*/
public function __construct(
?Lexer $lexer = null,
?Parser $parser = null,
?NodeTraverser $traverser = null,
?Standard $printer = null,
?NodeFinder $nodeFinder = null
) {
$this->lexer = $lexer ?? $this->defaultLexer();

$this->parser = $parser ?? new Php7($this->lexer);
$this->parser = $parser ?? (new ParserFactory())->createForNewestSupportedVersion();

if ($traverser === null) {
$traverser = new NodeTraverser();
Expand All @@ -92,18 +84,6 @@ public function __construct(
$this->nodeFinder = $nodeFinder ?? new NodeFinder();
}

/**
* @return Lexer
*/
private function defaultLexer(): Lexer
{
return new Emulative(
[
'usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos'],
]
);
}

/**
* Convert the given source code.
*
Expand All @@ -119,7 +99,7 @@ public function convert(string $code, array $functionCallMap): string
throw new RuntimeException('Code could not be parsed.');
}

$oldTokens = $this->lexer->getTokens();
$oldTokens = $this->parser->getTokens();

$newStmts = $this->traverser->traverse($oldStmts);

Expand Down
2 changes: 1 addition & 1 deletion tests/CodeConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testExceptionIfParserReturnsNull(): void
/** @var Parser $parser */
$parser = $parserProphecy->reveal();

$converter = new CodeConverter(null, $parser);
$converter = new CodeConverter($parser);
$converter->convert('<?php echo "1";', []);
}
}
Loading