Skip to content

Commit

Permalink
Merge pull request #10 from Stillat/update-php-parser
Browse files Browse the repository at this point in the history
Bump php-parser version to 5
  • Loading branch information
JohnathonKoster authored Aug 15, 2024
2 parents 116f1a0 + f6f30be commit 6c48a89
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"nikic/php-parser": "^4.10.3",
"nikic/php-parser": "^5",
"illuminate/support": "*"
},
"require-dev": {
Expand Down
4 changes: 2 additions & 2 deletions src/Evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function evaluate($node, $context = [])
} elseif ($node instanceof DNumber) {
return floatval($node->value);
} elseif ($node instanceof ConstFetch) {
return $this->getConstantValue($node->name->parts[0]);
return $this->getConstantValue($node->name->getParts()[0]);
} elseif ($node instanceof Array_) {
return $this->evaluateArray($node, $context);
} elseif ($node instanceof String_) {
Expand Down Expand Up @@ -62,7 +62,7 @@ protected function getNestedPath(PropertyFetch $propertyFetch)
protected function evaluateFunctionCall(FuncCall $funcCall, $context)
{
$runtimeMethod = new MethodCall();
$runtimeMethod->name = $funcCall->name->parts[0];
$runtimeMethod->name = $funcCall->name->getParts()[0];

foreach ($funcCall->args as $arg) {
if ($arg instanceof Arg) {
Expand Down
16 changes: 2 additions & 14 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Stillat\Primitives;

use Illuminate\Support\Str;
use PhpParser\Lexer\Emulative;
use PhpParser\Node\Arg;
use PhpParser\Parser\Php7;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;

class Parser
Expand All @@ -15,21 +15,9 @@ class Parser
*/
protected $parser;

/**
* @var Emulative
*/
protected $lexer = null;

public function __construct()
{
$this->lexer = new Emulative([
'usedAttributes' => [
'comments',
'startLine', 'endLine',
'startTokenPos', 'endTokenPos',
],
]);
$this->parser = new Php7($this->lexer);
$this->parser = (new ParserFactory())->createForNewestSupportedVersion();
}

/**
Expand Down

0 comments on commit 6c48a89

Please sign in to comment.