mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-14 12:32:00 +02:00
Updated Rector to commit f7caedf1b61070322bfb44bb266fbf26f8c993d3
f7caedf1b6
[Performance][PhpParser] Deprecate InlineCodeParser::parse(), extract into parseFile() and parseString() (#5482)
This commit is contained in:
parent
e7c602cd32
commit
e4d714cf5f
@ -126,7 +126,7 @@ CODE_SAMPLE
|
||||
{
|
||||
$content = $this->inlineCodeParser->stringify($expr);
|
||||
$content = '<?php $value = function(' . $content . ') {};';
|
||||
$nodes = $this->inlineCodeParser->parse($content);
|
||||
$nodes = $this->inlineCodeParser->parseString($content);
|
||||
/** @var Expression $expression */
|
||||
$expression = $nodes[0];
|
||||
/** @var Assign $assign */
|
||||
@ -146,8 +146,8 @@ CODE_SAMPLE
|
||||
// special case of code elsewhere
|
||||
return [$this->createEval($expr)];
|
||||
}
|
||||
$expr = $this->inlineCodeParser->stringify($expr);
|
||||
return $this->inlineCodeParser->parse($expr);
|
||||
$content = $this->inlineCodeParser->stringify($expr);
|
||||
return $this->inlineCodeParser->parseString($content);
|
||||
}
|
||||
private function createEval(Expr $expr) : Expression
|
||||
{
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '2d316449ada315992789eff3380e836adf997767';
|
||||
public const PACKAGE_VERSION = 'f7caedf1b61070322bfb44bb266fbf26f8c993d3';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-23 10:38:05';
|
||||
public const RELEASE_DATE = '2024-01-23 10:38:52';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -73,6 +73,9 @@ final class InlineCodeParser
|
||||
}
|
||||
/**
|
||||
* @return Stmt[]
|
||||
*
|
||||
* @api
|
||||
* @deprecated use parseFile() or parseString() instead
|
||||
*/
|
||||
public function parse(string $content) : array
|
||||
{
|
||||
@ -80,10 +83,22 @@ final class InlineCodeParser
|
||||
if (\is_file($content)) {
|
||||
$content = FileSystem::read($content);
|
||||
}
|
||||
// wrap code so php-parser can interpret it
|
||||
$content = StringUtils::isMatch($content, self::OPEN_PHP_TAG_REGEX) ? $content : '<?php ' . $content;
|
||||
$content = StringUtils::isMatch($content, self::ENDING_SEMI_COLON_REGEX) ? $content : $content . ';';
|
||||
return $this->simplePhpParser->parseString($content);
|
||||
return $this->parseCode($content);
|
||||
}
|
||||
/**
|
||||
* @return Stmt[]
|
||||
*/
|
||||
public function parseFile(string $fileName) : array
|
||||
{
|
||||
$fileContent = FileSystem::read($fileName);
|
||||
return $this->parseCode($fileContent);
|
||||
}
|
||||
/**
|
||||
* @return Stmt[]
|
||||
*/
|
||||
public function parseString(string $fileContent) : array
|
||||
{
|
||||
return $this->parseCode($fileContent);
|
||||
}
|
||||
public function stringify(Expr $expr) : string
|
||||
{
|
||||
@ -105,6 +120,16 @@ final class InlineCodeParser
|
||||
}
|
||||
return $this->betterStandardPrinter->print($expr);
|
||||
}
|
||||
/**
|
||||
* @return Stmt[]
|
||||
*/
|
||||
private function parseCode(string $code) : array
|
||||
{
|
||||
// wrap code so php-parser can interpret it
|
||||
$code = StringUtils::isMatch($code, self::OPEN_PHP_TAG_REGEX) ? $code : '<?php ' . $code;
|
||||
$code = StringUtils::isMatch($code, self::ENDING_SEMI_COLON_REGEX) ? $code : $code . ';';
|
||||
return $this->simplePhpParser->parseString($code);
|
||||
}
|
||||
private function resolveEncapsedValue(Encapsed $encapsed) : string
|
||||
{
|
||||
$value = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user