diff --git a/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php b/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php index 9f9a2bb5424..8059d591aa8 100644 --- a/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php +++ b/rules/Php72/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php @@ -126,7 +126,7 @@ CODE_SAMPLE { $content = $this->inlineCodeParser->stringify($expr); $content = '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 { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 4b7403fddea..22522e84744 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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 */ diff --git a/src/PhpParser/Parser/InlineCodeParser.php b/src/PhpParser/Parser/InlineCodeParser.php index 5f2da972c82..0e80251ad0c 100644 --- a/src/PhpParser/Parser/InlineCodeParser.php +++ b/src/PhpParser/Parser/InlineCodeParser.php @@ -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 : '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 : 'simplePhpParser->parseString($code); + } private function resolveEncapsedValue(Encapsed $encapsed) : string { $value = '';