Bug fixes with Php-Parser
This commit is contained in:
parent
923117999b
commit
be70823a79
30 changed files with 316 additions and 339 deletions
|
@ -31,27 +31,6 @@
|
||||||
|
|
||||||
class AstWalker
|
class AstWalker
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Returns an array representation of the node recursively
|
|
||||||
*
|
|
||||||
* @param array|Node $node
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function serialize(array|Node $node): array
|
|
||||||
{
|
|
||||||
if(is_array($node))
|
|
||||||
{
|
|
||||||
$serialized = [];
|
|
||||||
foreach($node as $sub_node)
|
|
||||||
{
|
|
||||||
$serialized[] = $sub_node->jsonSerialize();
|
|
||||||
}
|
|
||||||
return $serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node->jsonSerialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array of classes associated with the node recursively
|
* Returns an array of classes associated with the node recursively
|
||||||
*
|
*
|
||||||
|
@ -112,161 +91,4 @@
|
||||||
|
|
||||||
return $classes;
|
return $classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reconstructs nodes from an array representation recursively
|
|
||||||
*
|
|
||||||
* @param $value
|
|
||||||
* @return array|Comment|Node
|
|
||||||
* @noinspection PhpMissingReturnTypeInspection
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
public static function decodeRecursive($value)
|
|
||||||
{
|
|
||||||
if (is_array($value))
|
|
||||||
{
|
|
||||||
if (isset($value['nodeType']))
|
|
||||||
{
|
|
||||||
if ($value['nodeType'] === 'Comment' || $value['nodeType'] === 'Comment_Doc')
|
|
||||||
{
|
|
||||||
return self::decodeComment($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::decodeNode($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self::decodeArray($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Decodes an array by recursively decoding each value
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
* @return array
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
private static function decodeArray(array $array) : array
|
|
||||||
{
|
|
||||||
$decoded_array = [];
|
|
||||||
|
|
||||||
foreach ($array as $key => $value)
|
|
||||||
{
|
|
||||||
$decoded_array[$key] = self::decodeRecursive($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $decoded_array;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the node from the node type
|
|
||||||
*
|
|
||||||
* @param array $value
|
|
||||||
* @return Node
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
private static function decodeNode(array $value) : Node
|
|
||||||
{
|
|
||||||
$node_type = $value['nodeType'];
|
|
||||||
if (!is_string($node_type))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Node type must be a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Node $node */
|
|
||||||
$node = self::reflectionClassFromNodeType($node_type)->newInstanceWithoutConstructor();
|
|
||||||
|
|
||||||
if (isset($value['attributes'])) {
|
|
||||||
if (!is_array($value['attributes']))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Attributes must be an array');
|
|
||||||
}
|
|
||||||
|
|
||||||
$node->setAttributes(self::decodeArray($value['attributes']));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($value as $name => $sub_node) {
|
|
||||||
if ($name === 'nodeType' || $name === 'attributes')
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$node->$name = self::decodeRecursive($sub_node);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $node;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the comment from the node type
|
|
||||||
*
|
|
||||||
* @param array $value
|
|
||||||
* @return Comment
|
|
||||||
*/
|
|
||||||
private static function decodeComment(array $value): Comment
|
|
||||||
{
|
|
||||||
$class_name = $value['nodeType'] === 'Comment' ? Comment::class : Comment\Doc::class;
|
|
||||||
if (!isset($value['text']))
|
|
||||||
{
|
|
||||||
throw new RuntimeException('Comment must have text');
|
|
||||||
}
|
|
||||||
|
|
||||||
return new $class_name(
|
|
||||||
$value['text'],
|
|
||||||
$value['line'] ?? -1, $value['filePos'] ?? -1, $value['tokenPos'] ?? -1,
|
|
||||||
$value['endLine'] ?? -1, $value['endFilePos'] ?? -1, $value['endTokenPos'] ?? -1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the reflection class from the node type
|
|
||||||
*
|
|
||||||
* @param string $node_type
|
|
||||||
* @return ReflectionClass
|
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
|
||||||
private static function reflectionClassFromNodeType(string $node_type): ReflectionClass
|
|
||||||
{
|
|
||||||
return new ReflectionClass(self::classNameFromNodeType($node_type));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the class name from the node type
|
|
||||||
*
|
|
||||||
* @param string $nodeType
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private static function classNameFromNodeType(string $nodeType): string
|
|
||||||
{
|
|
||||||
$class_name = 'ncc\\ThirdParty\\nikic\\PhpParser\\Node\\' . str_replace('_', '\\', $nodeType);
|
|
||||||
if (class_exists($class_name))
|
|
||||||
{
|
|
||||||
return $class_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$class_name .= '_';
|
|
||||||
if (class_exists($class_name))
|
|
||||||
{
|
|
||||||
return $class_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("Unknown node type \"$nodeType\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms include, include_once, require and require_once statements into function calls.
|
|
||||||
*
|
|
||||||
* @param Node|array $stmts The AST node or array of nodes to transform.
|
|
||||||
* @param string|null $package Optionally. The package name to pass to the transformed function calls.
|
|
||||||
* @return Node|array The transformed AST node or array of nodes.
|
|
||||||
*/
|
|
||||||
public static function transformRequireCalls(Node|array $stmts, ?string $package=null): Node|array
|
|
||||||
{
|
|
||||||
$traverser = new NodeTraverser();
|
|
||||||
$traverser->addVisitor(new ExpressionTraverser($package));
|
|
||||||
|
|
||||||
return $traverser->traverse($stmts);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -30,7 +30,9 @@
|
||||||
use ncc\Exceptions\PathNotFoundException;
|
use ncc\Exceptions\PathNotFoundException;
|
||||||
use ncc\Extensions\ZiProto\ZiProto;
|
use ncc\Extensions\ZiProto\ZiProto;
|
||||||
use ncc\Objects\Package\Component;
|
use ncc\Objects\Package\Component;
|
||||||
|
use ncc\ThirdParty\nikic\PhpParser\NodeDumper;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
|
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
|
||||||
|
use ncc\ThirdParty\nikic\PhpParser\PhpVersion;
|
||||||
use ncc\Utilities\Base64;
|
use ncc\Utilities\Base64;
|
||||||
use ncc\Utilities\Console;
|
use ncc\Utilities\Console;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
@ -52,12 +54,8 @@
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$stmts = (new ParserFactory())->create(ParserFactory::PREFER_PHP7)->parse(IO::fread($file_path));
|
$stmts = ((new ParserFactory())->createForNewestSupportedVersion())->parse(IO::fread($file_path));
|
||||||
$stmts = AstWalker::transformRequireCalls(
|
$component = new Component($component_name, ZiProto::encode(Serializer::nodesToArray($stmts)), ComponentDataType::AST);
|
||||||
$stmts, $this->getProjectManager()->getProjectConfiguration()->getAssembly()->getPackage()
|
|
||||||
);
|
|
||||||
|
|
||||||
$component = new Component($component_name, ZiProto::encode($stmts), ComponentDataType::AST);
|
|
||||||
$component->addFlag(ComponentFlags::PHP_AST->value);
|
$component->addFlag(ComponentFlags::PHP_AST->value);
|
||||||
$pointer = $package_writer->addComponent($component);
|
$pointer = $package_writer->addComponent($component);
|
||||||
|
|
||||||
|
|
151
src/ncc/Classes/PhpExtension/Serializer.php
Normal file
151
src/ncc/Classes/PhpExtension/Serializer.php
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright (c) Nosial 2022-2024, all rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||||
|
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
|
||||||
|
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
|
||||||
|
* conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
|
||||||
|
* of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||||
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
* DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace ncc\Classes\PhpExtension;
|
||||||
|
|
||||||
|
use ncc\ThirdParty\nikic\PhpParser\Comment;
|
||||||
|
use ncc\ThirdParty\nikic\PhpParser\Node;
|
||||||
|
use ncc\ThirdParty\nikic\PhpParser\NodeAbstract;
|
||||||
|
use ReflectionClass;
|
||||||
|
use RuntimeException;
|
||||||
|
use function is_array;
|
||||||
|
use function is_string;
|
||||||
|
|
||||||
|
class Serializer
|
||||||
|
{
|
||||||
|
/** @var ReflectionClass<Node>[] Node type to reflection class map */
|
||||||
|
private static array $reflectionClassCache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param NodeAbstract[] $nodeAbstracts
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function nodesToArray(array $nodeAbstracts): array
|
||||||
|
{
|
||||||
|
$serialized = [];
|
||||||
|
|
||||||
|
foreach ($nodeAbstracts as $nodeAbstract)
|
||||||
|
{
|
||||||
|
$serialized[] = $nodeAbstract->jsonSerialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $nodeAbstracts
|
||||||
|
* @return NodeAbstract[]
|
||||||
|
*/
|
||||||
|
public static function arrayToNodes(array $nodeAbstracts): array
|
||||||
|
{
|
||||||
|
return self::decodeRecursive($nodeAbstracts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private static function decodeRecursive($value) {
|
||||||
|
if (is_array($value)) {
|
||||||
|
if (isset($value['nodeType'])) {
|
||||||
|
if ($value['nodeType'] === 'Comment' || $value['nodeType'] === 'Comment_Doc') {
|
||||||
|
return self::decodeComment($value);
|
||||||
|
}
|
||||||
|
return self::decodeNode($value);
|
||||||
|
}
|
||||||
|
return self::decodeArray($value);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function decodeArray(array $array): array {
|
||||||
|
$decodedArray = [];
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
$decodedArray[$key] = self::decodeRecursive($value);
|
||||||
|
}
|
||||||
|
return $decodedArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function decodeNode(array $value): Node {
|
||||||
|
$nodeType = $value['nodeType'];
|
||||||
|
if (!is_string($nodeType)) {
|
||||||
|
throw new RuntimeException('Node type must be a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
$reflectionClass = self::reflectionClassFromNodeType($nodeType);
|
||||||
|
$node = $reflectionClass->newInstanceWithoutConstructor();
|
||||||
|
|
||||||
|
if (isset($value['attributes'])) {
|
||||||
|
if (!is_array($value['attributes'])) {
|
||||||
|
throw new RuntimeException('Attributes must be an array');
|
||||||
|
}
|
||||||
|
|
||||||
|
$node->setAttributes(self::decodeArray($value['attributes']));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($value as $name => $subNode) {
|
||||||
|
if ($name === 'nodeType' || $name === 'attributes') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$node->$name = self::decodeRecursive($subNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function decodeComment(array $value): Comment {
|
||||||
|
$className = $value['nodeType'] === 'Comment' ? Comment::class : Comment\Doc::class;
|
||||||
|
if (!isset($value['text'])) {
|
||||||
|
throw new RuntimeException('Comment must have text');
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $className(
|
||||||
|
$value['text'],
|
||||||
|
$value['line'] ?? -1, $value['filePos'] ?? -1, $value['tokenPos'] ?? -1,
|
||||||
|
$value['endLine'] ?? -1, $value['endFilePos'] ?? -1, $value['endTokenPos'] ?? -1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function reflectionClassFromNodeType(string $nodeType): ReflectionClass {
|
||||||
|
if (!isset(self::$reflectionClassCache[$nodeType])) {
|
||||||
|
$className = self::classNameFromNodeType($nodeType);
|
||||||
|
self::$reflectionClassCache[$nodeType] = new ReflectionClass($className);
|
||||||
|
}
|
||||||
|
return self::$reflectionClassCache[$nodeType];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return class-string<Node> */
|
||||||
|
private static function classNameFromNodeType(string $nodeType): string {
|
||||||
|
$className = '\\ncc\\ThirdParty\\nikic\\PhpParser\\Node\\' . strtr($nodeType, '_', '\\');
|
||||||
|
if (class_exists($className)) {
|
||||||
|
return $className;
|
||||||
|
}
|
||||||
|
|
||||||
|
$className .= '_';
|
||||||
|
if (class_exists($className)) {
|
||||||
|
return $className;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Unknown node type \"$nodeType\"");
|
||||||
|
}
|
||||||
|
}
|
|
@ -162,7 +162,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException('Importing from a package name is not supported yet');
|
throw new RuntimeException(sprintf('Failed to import package "%s" because it does not exist', $package));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use ncc\Classes\PhpExtension\AstWalker;
|
use ncc\Classes\PhpExtension\AstWalker;
|
||||||
|
use ncc\Classes\PhpExtension\Serializer;
|
||||||
use ncc\Enums\Flags\ComponentFlags;
|
use ncc\Enums\Flags\ComponentFlags;
|
||||||
use ncc\Enums\LogLevel;
|
use ncc\Enums\LogLevel;
|
||||||
use ncc\Enums\Options\ComponentDecodeOptions;
|
use ncc\Enums\Options\ComponentDecodeOptions;
|
||||||
|
@ -177,12 +178,15 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$decodedData = base64_decode($this->data);
|
||||||
|
$ast = Serializer::arrayToNodes((array)$decodedData);
|
||||||
|
|
||||||
if(in_array(ComponentDecodeOptions::AS_FILE->value, $options, true))
|
if(in_array(ComponentDecodeOptions::AS_FILE->value, $options, true))
|
||||||
{
|
{
|
||||||
return (new Standard())->prettyPrintFile(AstWalker::decodeRecursive(base64_decode($this->data)));
|
return (new Standard())->prettyPrintFile($ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new Standard())->prettyPrint(AstWalker::decodeRecursive(base64_decode($this->data)));
|
return (new Standard())->prettyPrint($ast);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
@ -197,12 +201,15 @@
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
$decodedData = ZiProto::decode($this->data);
|
||||||
|
$ast = Serializer::arrayToNodes($decodedData);
|
||||||
|
|
||||||
if(in_array(ComponentDecodeOptions::AS_FILE->value, $options, true))
|
if(in_array(ComponentDecodeOptions::AS_FILE->value, $options, true))
|
||||||
{
|
{
|
||||||
return (new Standard())->prettyPrintFile(AstWalker::decodeRecursive(ZiProto::decode($this->data)));
|
return (new Standard())->prettyPrintFile($ast);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new Standard())->prettyPrint(AstWalker::decodeRecursive(ZiProto::decode($this->data)));
|
return (new Standard())->prettyPrint($ast);
|
||||||
}
|
}
|
||||||
catch(Exception $e)
|
catch(Exception $e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,10 +7,10 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use PhpParser\Modifiers;
|
use PhpParser\Modifiers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Const_;
|
use PhpParser\Node\Const_;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class ClassConst implements PhpParser\Builder {
|
class ClassConst implements PhpParser\Builder {
|
||||||
protected int $flags = 0;
|
protected int $flags = 0;
|
||||||
|
|
|
@ -5,9 +5,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use PhpParser\Modifiers;
|
use PhpParser\Modifiers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Class_ extends Declaration {
|
class Class_ extends Declaration {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -12,7 +12,7 @@ abstract class Declaration implements PhpParser\Builder {
|
||||||
/**
|
/**
|
||||||
* Adds a statement.
|
* Adds a statement.
|
||||||
*
|
*
|
||||||
* @param \ncc\ThirdParty\nikic\PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add
|
* @param PhpParser\Node\Stmt|PhpParser\Builder $stmt The statement to add
|
||||||
*
|
*
|
||||||
* @return $this The builder instance (for fluid interface)
|
* @return $this The builder instance (for fluid interface)
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,7 @@ abstract class Declaration implements PhpParser\Builder {
|
||||||
/**
|
/**
|
||||||
* Adds multiple statements.
|
* Adds multiple statements.
|
||||||
*
|
*
|
||||||
* @param (\ncc\ThirdParty\nikic\PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add
|
* @param (PhpParser\Node\Stmt|PhpParser\Builder)[] $stmts The statements to add
|
||||||
*
|
*
|
||||||
* @return $this The builder instance (for fluid interface)
|
* @return $this The builder instance (for fluid interface)
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,9 +6,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class EnumCase implements PhpParser\Builder {
|
class EnumCase implements PhpParser\Builder {
|
||||||
/** @var Identifier|string */
|
/** @var Identifier|string */
|
||||||
|
|
|
@ -4,10 +4,10 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Enum_ extends Declaration {
|
class Enum_ extends Declaration {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Function_ extends FunctionLike {
|
class Function_ extends FunctionLike {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -4,9 +4,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Interface_ extends Declaration {
|
class Interface_ extends Declaration {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -5,8 +5,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use PhpParser\Modifiers;
|
use PhpParser\Modifiers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Method extends FunctionLike {
|
class Method extends FunctionLike {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Namespace_ extends Declaration {
|
class Namespace_ extends Declaration {
|
||||||
private ?Node\Name $name;
|
private ?Node\Name $name;
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use PhpParser\Modifiers;
|
use PhpParser\Modifiers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
|
|
||||||
class Param implements PhpParser\Builder {
|
class Param implements PhpParser\Builder {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -5,11 +5,11 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use PhpParser\Modifiers;
|
use PhpParser\Modifiers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Identifier;
|
use PhpParser\Node\Identifier;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Name;
|
use PhpParser\Node\Name;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\ComplexType;
|
use PhpParser\Node\ComplexType;
|
||||||
|
|
||||||
class Property implements PhpParser\Builder {
|
class Property implements PhpParser\Builder {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -135,9 +135,9 @@ class TraitUseAdaptation implements Builder {
|
||||||
public function getNode(): Node {
|
public function getNode(): Node {
|
||||||
switch ($this->type) {
|
switch ($this->type) {
|
||||||
case self::TYPE_ALIAS:
|
case self::TYPE_ALIAS:
|
||||||
return new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias);
|
return new Stmt\TraitUseAdaptation\Alias($this->trait, $this->method, $this->modifier, $this->alias);
|
||||||
case self::TYPE_PRECEDENCE:
|
case self::TYPE_PRECEDENCE:
|
||||||
return new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence($this->trait, $this->method, $this->insteadof);
|
return new Stmt\TraitUseAdaptation\Precedence($this->trait, $this->method, $this->insteadof);
|
||||||
default:
|
default:
|
||||||
throw new \LogicException('Type of adaptation is not defined');
|
throw new \LogicException('Type of adaptation is not defined');
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder;
|
||||||
|
|
||||||
use ncc\ThirdParty\nikic\PhpParser;
|
use ncc\ThirdParty\nikic\PhpParser;
|
||||||
use PhpParser\BuilderHelpers;
|
use PhpParser\BuilderHelpers;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node;
|
use PhpParser\Node;
|
||||||
use ncc\ThirdParty\nikic\PhpParser\Node\Stmt;
|
use PhpParser\Node\Stmt;
|
||||||
|
|
||||||
class Trait_ extends Declaration {
|
class Trait_ extends Declaration {
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
|
@ -17,8 +17,8 @@ class BuilderFactory {
|
||||||
* @param string|Name $name Name of the attribute
|
* @param string|Name $name Name of the attribute
|
||||||
* @param array $args Attribute named arguments
|
* @param array $args Attribute named arguments
|
||||||
*/
|
*/
|
||||||
public function attribute($name, array $args = []): ncc\ThirdParty\nikic\PhpParser\Node\Attribute {
|
public function attribute($name, array $args = []): Node\Attribute {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Node\Attribute(
|
return new Node\Attribute(
|
||||||
BuilderHelpers::normalizeName($name),
|
BuilderHelpers::normalizeName($name),
|
||||||
$this->args($args)
|
$this->args($args)
|
||||||
);
|
);
|
||||||
|
@ -27,12 +27,12 @@ class BuilderFactory {
|
||||||
/**
|
/**
|
||||||
* Creates a namespace builder.
|
* Creates a namespace builder.
|
||||||
*
|
*
|
||||||
* @param null|string|ncc\ThirdParty\nikic\PhpParser\Node\Name $name Name of the namespace
|
* @param null|string|Node\Name $name Name of the namespace
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Namespace_ The created namespace builder
|
* @return Builder\Namespace_ The created namespace builder
|
||||||
*/
|
*/
|
||||||
public function namespace($name): ncc\ThirdParty\nikic\PhpParser\Builder\Namespace_ {
|
public function namespace($name): Builder\Namespace_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Namespace_($name);
|
return new Builder\Namespace_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,10 +40,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the class
|
* @param string $name Name of the class
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Class_ The created class builder
|
* @return Builder\Class_ The created class builder
|
||||||
*/
|
*/
|
||||||
public function class(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Class_ {
|
public function class(string $name): Builder\Class_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Class_($name);
|
return new Builder\Class_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,10 +51,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the interface
|
* @param string $name Name of the interface
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Interface_ The created interface builder
|
* @return Builder\Interface_ The created interface builder
|
||||||
*/
|
*/
|
||||||
public function interface(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Interface_ {
|
public function interface(string $name): Builder\Interface_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Interface_($name);
|
return new Builder\Interface_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,10 +62,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the trait
|
* @param string $name Name of the trait
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Trait_ The created trait builder
|
* @return Builder\Trait_ The created trait builder
|
||||||
*/
|
*/
|
||||||
public function trait(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Trait_ {
|
public function trait(string $name): Builder\Trait_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Trait_($name);
|
return new Builder\Trait_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,38 +73,38 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the enum
|
* @param string $name Name of the enum
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Enum_ The created enum builder
|
* @return Builder\Enum_ The created enum builder
|
||||||
*/
|
*/
|
||||||
public function enum(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Enum_ {
|
public function enum(string $name): Builder\Enum_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Enum_($name);
|
return new Builder\Enum_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a trait use builder.
|
* Creates a trait use builder.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string ...$traits Trait names
|
* @param Node\Name|string ...$traits Trait names
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\TraitUse The created trait use builder
|
* @return Builder\TraitUse The created trait use builder
|
||||||
*/
|
*/
|
||||||
public function useTrait(...$traits): ncc\ThirdParty\nikic\PhpParser\Builder\TraitUse {
|
public function useTrait(...$traits): Builder\TraitUse {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\TraitUse(...$traits);
|
return new Builder\TraitUse(...$traits);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a trait use adaptation builder.
|
* Creates a trait use adaptation builder.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string|null $trait Trait name
|
* @param Node\Name|string|null $trait Trait name
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Identifier|string $method Method name
|
* @param Node\Identifier|string $method Method name
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\TraitUseAdaptation The created trait use adaptation builder
|
* @return Builder\TraitUseAdaptation The created trait use adaptation builder
|
||||||
*/
|
*/
|
||||||
public function traitUseAdaptation($trait, $method = null): ncc\ThirdParty\nikic\PhpParser\Builder\TraitUseAdaptation {
|
public function traitUseAdaptation($trait, $method = null): Builder\TraitUseAdaptation {
|
||||||
if ($method === null) {
|
if ($method === null) {
|
||||||
$method = $trait;
|
$method = $trait;
|
||||||
$trait = null;
|
$trait = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\TraitUseAdaptation($trait, $method);
|
return new Builder\TraitUseAdaptation($trait, $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,10 +112,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the method
|
* @param string $name Name of the method
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Method The created method builder
|
* @return Builder\Method The created method builder
|
||||||
*/
|
*/
|
||||||
public function method(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Method {
|
public function method(string $name): Builder\Method {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Method($name);
|
return new Builder\Method($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,10 +123,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the parameter
|
* @param string $name Name of the parameter
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Param The created parameter builder
|
* @return Builder\Param The created parameter builder
|
||||||
*/
|
*/
|
||||||
public function param(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Param {
|
public function param(string $name): Builder\Param {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Param($name);
|
return new Builder\Param($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,10 +134,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the property
|
* @param string $name Name of the property
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Property The created property builder
|
* @return Builder\Property The created property builder
|
||||||
*/
|
*/
|
||||||
public function property(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Property {
|
public function property(string $name): Builder\Property {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Property($name);
|
return new Builder\Property($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,55 +145,55 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string $name Name of the function
|
* @param string $name Name of the function
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Function_ The created function builder
|
* @return Builder\Function_ The created function builder
|
||||||
*/
|
*/
|
||||||
public function function(string $name): ncc\ThirdParty\nikic\PhpParser\Builder\Function_ {
|
public function function(string $name): Builder\Function_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Function_($name);
|
return new Builder\Function_($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a namespace/class use builder.
|
* Creates a namespace/class use builder.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string $name Name of the entity (namespace or class) to alias
|
* @param Node\Name|string $name Name of the entity (namespace or class) to alias
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Use_ The created use builder
|
* @return Builder\Use_ The created use builder
|
||||||
*/
|
*/
|
||||||
public function use($name): ncc\ThirdParty\nikic\PhpParser\Builder\Use_ {
|
public function use($name): Builder\Use_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_NORMAL);
|
return new Builder\Use_($name, Use_::TYPE_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function use builder.
|
* Creates a function use builder.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string $name Name of the function to alias
|
* @param Node\Name|string $name Name of the function to alias
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Use_ The created use function builder
|
* @return Builder\Use_ The created use function builder
|
||||||
*/
|
*/
|
||||||
public function useFunction($name): ncc\ThirdParty\nikic\PhpParser\Builder\Use_ {
|
public function useFunction($name): Builder\Use_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_FUNCTION);
|
return new Builder\Use_($name, Use_::TYPE_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a constant use builder.
|
* Creates a constant use builder.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string $name Name of the const to alias
|
* @param Node\Name|string $name Name of the const to alias
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\Use_ The created use const builder
|
* @return Builder\Use_ The created use const builder
|
||||||
*/
|
*/
|
||||||
public function useConst($name): ncc\ThirdParty\nikic\PhpParser\Builder\Use_ {
|
public function useConst($name): Builder\Use_ {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_CONSTANT);
|
return new Builder\Use_($name, Use_::TYPE_CONSTANT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a class constant builder.
|
* Creates a class constant builder.
|
||||||
*
|
*
|
||||||
* @param string|Identifier $name Name
|
* @param string|Identifier $name Name
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Expr|bool|null|int|float|string|array $value Value
|
* @param Node\Expr|bool|null|int|float|string|array $value Value
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\ClassConst The created use const builder
|
* @return Builder\ClassConst The created use const builder
|
||||||
*/
|
*/
|
||||||
public function classConst($name, $value): ncc\ThirdParty\nikic\PhpParser\Builder\ClassConst {
|
public function classConst($name, $value): Builder\ClassConst {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\ClassConst($name, $value);
|
return new Builder\ClassConst($name, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,10 +201,10 @@ class BuilderFactory {
|
||||||
*
|
*
|
||||||
* @param string|Identifier $name Name
|
* @param string|Identifier $name Name
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Builder\EnumCase The created use const builder
|
* @return Builder\EnumCase The created use const builder
|
||||||
*/
|
*/
|
||||||
public function enumCase($name): ncc\ThirdParty\nikic\PhpParser\Builder\EnumCase {
|
public function enumCase($name): Builder\EnumCase {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Builder\EnumCase($name);
|
return new Builder\EnumCase($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -215,12 +215,12 @@ final class BuilderHelpers {
|
||||||
* Normalizes a value: Converts nulls, booleans, integers,
|
* Normalizes a value: Converts nulls, booleans, integers,
|
||||||
* floats, strings and arrays into their respective nodes
|
* floats, strings and arrays into their respective nodes
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Expr|bool|null|int|float|string|array|\UnitEnum $value The value to normalize
|
* @param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value The value to normalize
|
||||||
*
|
*
|
||||||
* @return Expr The normalized value
|
* @return Expr The normalized value
|
||||||
*/
|
*/
|
||||||
public static function normalizeValue($value): Expr {
|
public static function normalizeValue($value): Expr {
|
||||||
if ($value instanceof ncc\ThirdParty\nikic\PhpParser\Node\Expr) {
|
if ($value instanceof Node\Expr) {
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,12 +254,12 @@ final class BuilderHelpers {
|
||||||
foreach ($value as $itemKey => $itemValue) {
|
foreach ($value as $itemKey => $itemValue) {
|
||||||
// for consecutive, numeric keys don't generate keys
|
// for consecutive, numeric keys don't generate keys
|
||||||
if (null !== $lastKey && ++$lastKey === $itemKey) {
|
if (null !== $lastKey && ++$lastKey === $itemKey) {
|
||||||
$items[] = new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem(
|
$items[] = new Node\ArrayItem(
|
||||||
self::normalizeValue($itemValue)
|
self::normalizeValue($itemValue)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$lastKey = null;
|
$lastKey = null;
|
||||||
$items[] = new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem(
|
$items[] = new Node\ArrayItem(
|
||||||
self::normalizeValue($itemValue),
|
self::normalizeValue($itemValue),
|
||||||
self::normalizeValue($itemKey)
|
self::normalizeValue($itemKey)
|
||||||
);
|
);
|
||||||
|
@ -298,20 +298,20 @@ final class BuilderHelpers {
|
||||||
/**
|
/**
|
||||||
* Normalizes a attribute: Converts attribute to the Attribute Group if needed.
|
* Normalizes a attribute: Converts attribute to the Attribute Group if needed.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Attribute|ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup $attribute
|
* @param Node\Attribute|Node\AttributeGroup $attribute
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup The Attribute Group
|
* @return Node\AttributeGroup The Attribute Group
|
||||||
*/
|
*/
|
||||||
public static function normalizeAttribute($attribute): ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup {
|
public static function normalizeAttribute($attribute): Node\AttributeGroup {
|
||||||
if ($attribute instanceof ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup) {
|
if ($attribute instanceof Node\AttributeGroup) {
|
||||||
return $attribute;
|
return $attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($attribute instanceof ncc\ThirdParty\nikic\PhpParser\Node\Attribute)) {
|
if (!($attribute instanceof Node\Attribute)) {
|
||||||
throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup');
|
throw new \LogicException('Attribute must be an instance of PhpParser\Node\Attribute or PhpParser\Node\AttributeGroup');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup([$attribute]);
|
return new Node\AttributeGroup([$attribute]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
namespace ncc\ThirdParty\nikic\PhpParser\Internal;
|
namespace ncc\ThirdParty\nikic\PhpParser\Internal;
|
||||||
|
|
||||||
if (\PHP_VERSION_ID >= 80000) {
|
if (\PHP_VERSION_ID >= 80000) {
|
||||||
class TokenPolyfill extends \PhpToken {
|
class_alias(\PhpToken::class, TokenPolyfill::class);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function ensureReplacementReasonable(Node $old, Node $new): void {
|
private function ensureReplacementReasonable(Node $old, Node $new): void {
|
||||||
if ($old instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt && $new instanceof ncc\ThirdParty\nikic\PhpParser\Node\Expr) {
|
if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
|
||||||
throw new \LogicException(
|
throw new \LogicException(
|
||||||
"Trying to replace statement ({$old->getType()}) " .
|
"Trying to replace statement ({$old->getType()}) " .
|
||||||
"with expression ({$new->getType()}). Are you missing a " .
|
"with expression ({$new->getType()}). Are you missing a " .
|
||||||
|
@ -268,7 +268,7 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($old instanceof ncc\ThirdParty\nikic\PhpParser\Node\Expr && $new instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt) {
|
if ($old instanceof Node\Expr && $new instanceof Node\Stmt) {
|
||||||
throw new \LogicException(
|
throw new \LogicException(
|
||||||
"Trying to replace expression ({$old->getType()}) " .
|
"Trying to replace expression ({$old->getType()}) " .
|
||||||
"with statement ({$new->getType()})"
|
"with statement ({$new->getType()})"
|
||||||
|
|
|
@ -156,7 +156,7 @@ class NameResolver extends NodeVisitorAbstract {
|
||||||
$adaptation->trait = $this->resolveClassName($adaptation->trait);
|
$adaptation->trait = $this->resolveClassName($adaptation->trait);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($adaptation instanceof \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence) {
|
if ($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) {
|
||||||
foreach ($adaptation->insteadof as &$insteadof) {
|
foreach ($adaptation->insteadof as &$insteadof) {
|
||||||
$insteadof = $this->resolveClassName($insteadof);
|
$insteadof = $this->resolveClassName($insteadof);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface Parser {
|
||||||
* @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
|
* @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
|
||||||
* to ErrorHandler\Throwing.
|
* to ErrorHandler\Throwing.
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
|
* @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
|
||||||
* the parser was unable to recover from an error).
|
* the parser was unable to recover from an error).
|
||||||
*/
|
*/
|
||||||
public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array;
|
public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array;
|
||||||
|
|
|
@ -2027,19 +2027,19 @@ class Php7 extends \ncc\ThirdParty\nikic\PhpParser\ParserAbstract
|
||||||
$self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)];
|
$self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)];
|
||||||
},
|
},
|
||||||
357 => static function ($self, $stackPos) {
|
357 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
358 => static function ($self, $stackPos) {
|
358 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
359 => static function ($self, $stackPos) {
|
359 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
360 => static function ($self, $stackPos) {
|
360 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
361 => static function ($self, $stackPos) {
|
361 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
362 => static function ($self, $stackPos) {
|
362 => static function ($self, $stackPos) {
|
||||||
$self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]);
|
$self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]);
|
||||||
|
|
|
@ -2042,19 +2042,19 @@ class Php8 extends \ncc\ThirdParty\nikic\PhpParser\ParserAbstract
|
||||||
$self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)];
|
$self->semStack[$stackPos-(2-1)][] = $self->semStack[$stackPos-(2-2)]; $self->semValue = $self->semStack[$stackPos-(2-1)];
|
||||||
},
|
},
|
||||||
358 => static function ($self, $stackPos) {
|
358 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Precedence($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
359 => static function ($self, $stackPos) {
|
359 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(5-1)][0], $self->semStack[$stackPos-(5-1)][1], $self->semStack[$stackPos-(5-3)], $self->semStack[$stackPos-(5-4)], $self->getAttributes($self->tokenStartStack[$stackPos-(5-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
360 => static function ($self, $stackPos) {
|
360 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], $self->semStack[$stackPos-(4-3)], null, $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
361 => static function ($self, $stackPos) {
|
361 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
362 => static function ($self, $stackPos) {
|
362 => static function ($self, $stackPos) {
|
||||||
$self->semValue = new \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
$self->semValue = new Stmt\TraitUseAdaptation\Alias($self->semStack[$stackPos-(4-1)][0], $self->semStack[$stackPos-(4-1)][1], null, $self->semStack[$stackPos-(4-3)], $self->getAttributes($self->tokenStartStack[$stackPos-(4-1)], $self->tokenEndStack[$stackPos]));
|
||||||
},
|
},
|
||||||
363 => static function ($self, $stackPos) {
|
363 => static function ($self, $stackPos) {
|
||||||
$self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]);
|
$self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]);
|
||||||
|
|
|
@ -174,7 +174,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
* @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
|
* @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
|
||||||
* to ErrorHandler\Throwing.
|
* to ErrorHandler\Throwing.
|
||||||
*
|
*
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
|
* @return Node\Stmt[]|null Array of statements (or null non-throwing error handler is used and
|
||||||
* the parser was unable to recover from an error).
|
* the parser was unable to recover from an error).
|
||||||
*/
|
*/
|
||||||
public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array {
|
public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array {
|
||||||
|
@ -555,8 +555,8 @@ abstract class ParserAbstract implements Parser {
|
||||||
/**
|
/**
|
||||||
* Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
|
* Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
|
||||||
*
|
*
|
||||||
* @param ncc\ThirdParty\nikic\PhpParser\Node\Stmt[] $stmts
|
* @param Node\Stmt[] $stmts
|
||||||
* @return ncc\ThirdParty\nikic\PhpParser\Node\Stmt[]
|
* @return Node\Stmt[]
|
||||||
*/
|
*/
|
||||||
protected function handleNamespaces(array $stmts): array {
|
protected function handleNamespaces(array $stmts): array {
|
||||||
$hasErrored = false;
|
$hasErrored = false;
|
||||||
|
@ -569,10 +569,10 @@ abstract class ParserAbstract implements Parser {
|
||||||
// For braced namespaces we only have to check that there are no invalid statements between the namespaces
|
// For braced namespaces we only have to check that there are no invalid statements between the namespaces
|
||||||
$afterFirstNamespace = false;
|
$afterFirstNamespace = false;
|
||||||
foreach ($stmts as $stmt) {
|
foreach ($stmts as $stmt) {
|
||||||
if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_) {
|
if ($stmt instanceof Node\Stmt\Namespace_) {
|
||||||
$afterFirstNamespace = true;
|
$afterFirstNamespace = true;
|
||||||
} elseif (!$stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\HaltCompiler
|
} elseif (!$stmt instanceof Node\Stmt\HaltCompiler
|
||||||
&& !$stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Nop
|
&& !$stmt instanceof Node\Stmt\Nop
|
||||||
&& $afterFirstNamespace && !$hasErrored) {
|
&& $afterFirstNamespace && !$hasErrored) {
|
||||||
$this->emitError(new Error(
|
$this->emitError(new Error(
|
||||||
'No code may exist outside of namespace {}', $stmt->getAttributes()));
|
'No code may exist outside of namespace {}', $stmt->getAttributes()));
|
||||||
|
@ -586,7 +586,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
$targetStmts = &$resultStmts;
|
$targetStmts = &$resultStmts;
|
||||||
$lastNs = null;
|
$lastNs = null;
|
||||||
foreach ($stmts as $stmt) {
|
foreach ($stmts as $stmt) {
|
||||||
if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_) {
|
if ($stmt instanceof Node\Stmt\Namespace_) {
|
||||||
if ($lastNs !== null) {
|
if ($lastNs !== null) {
|
||||||
$this->fixupNamespaceAttributes($lastNs);
|
$this->fixupNamespaceAttributes($lastNs);
|
||||||
}
|
}
|
||||||
|
@ -600,7 +600,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
$targetStmts = &$resultStmts;
|
$targetStmts = &$resultStmts;
|
||||||
}
|
}
|
||||||
$lastNs = $stmt;
|
$lastNs = $stmt;
|
||||||
} elseif ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\HaltCompiler) {
|
} elseif ($stmt instanceof Node\Stmt\HaltCompiler) {
|
||||||
// __halt_compiler() is not moved into the namespace
|
// __halt_compiler() is not moved into the namespace
|
||||||
$resultStmts[] = $stmt;
|
$resultStmts[] = $stmt;
|
||||||
} else {
|
} else {
|
||||||
|
@ -614,7 +614,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fixupNamespaceAttributes(ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_ $stmt): void {
|
private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt): void {
|
||||||
// We moved the statements into the namespace node, as such the end of the namespace node
|
// We moved the statements into the namespace node, as such the end of the namespace node
|
||||||
// needs to be extended to the end of the statements.
|
// needs to be extended to the end of the statements.
|
||||||
if (empty($stmt->stmts)) {
|
if (empty($stmt->stmts)) {
|
||||||
|
@ -659,7 +659,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
$style = null;
|
$style = null;
|
||||||
$hasNotAllowedStmts = false;
|
$hasNotAllowedStmts = false;
|
||||||
foreach ($stmts as $i => $stmt) {
|
foreach ($stmts as $i => $stmt) {
|
||||||
if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_) {
|
if ($stmt instanceof Node\Stmt\Namespace_) {
|
||||||
$currentStyle = null === $stmt->stmts ? 'semicolon' : 'brace';
|
$currentStyle = null === $stmt->stmts ? 'semicolon' : 'brace';
|
||||||
if (null === $style) {
|
if (null === $style) {
|
||||||
$style = $currentStyle;
|
$style = $currentStyle;
|
||||||
|
@ -681,14 +681,14 @@ abstract class ParserAbstract implements Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* declare(), __halt_compiler() and nops can be used before a namespace declaration */
|
/* declare(), __halt_compiler() and nops can be used before a namespace declaration */
|
||||||
if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Declare_
|
if ($stmt instanceof Node\Stmt\Declare_
|
||||||
|| $stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\HaltCompiler
|
|| $stmt instanceof Node\Stmt\HaltCompiler
|
||||||
|| $stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Nop) {
|
|| $stmt instanceof Node\Stmt\Nop) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There may be a hashbang line at the very start of the file */
|
/* There may be a hashbang line at the very start of the file */
|
||||||
if ($i === 0 && $stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\InlineHTML && preg_match('/\A#!.*\r?\n\z/', $stmt->value)) {
|
if ($i === 0 && $stmt instanceof Node\Stmt\InlineHTML && preg_match('/\A#!.*\r?\n\z/', $stmt->value)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,7 +709,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Node\Identifier($lowerName, $name->getAttributes());
|
return new Node\Identifier($lowerName, $name->getAttributes());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -860,7 +860,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
return new String_($contents, $attributes);
|
return new String_($contents, $attributes);
|
||||||
} else {
|
} else {
|
||||||
assert(count($contents) > 0);
|
assert(count($contents) > 0);
|
||||||
if (!$contents[0] instanceof ncc\ThirdParty\nikic\PhpParser\Node\InterpolatedStringPart) {
|
if (!$contents[0] instanceof Node\InterpolatedStringPart) {
|
||||||
// If there is no leading encapsed string part, pretend there is an empty one
|
// If there is no leading encapsed string part, pretend there is an empty one
|
||||||
$this->stripIndentation(
|
$this->stripIndentation(
|
||||||
'', $indentLen, $indentChar, true, false, $contents[0]->getAttributes()
|
'', $indentLen, $indentChar, true, false, $contents[0]->getAttributes()
|
||||||
|
@ -869,7 +869,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
|
|
||||||
$newContents = [];
|
$newContents = [];
|
||||||
foreach ($contents as $i => $part) {
|
foreach ($contents as $i => $part) {
|
||||||
if ($part instanceof ncc\ThirdParty\nikic\PhpParser\Node\InterpolatedStringPart) {
|
if ($part instanceof Node\InterpolatedStringPart) {
|
||||||
$isLast = $i === \count($contents) - 1;
|
$isLast = $i === \count($contents) - 1;
|
||||||
$part->value = $this->stripIndentation(
|
$part->value = $this->stripIndentation(
|
||||||
$part->value, $indentLen, $indentChar,
|
$part->value, $indentLen, $indentChar,
|
||||||
|
@ -977,13 +977,13 @@ abstract class ParserAbstract implements Parser {
|
||||||
|
|
||||||
protected function fixupArrayDestructuring(Array_ $node): Expr\List_ {
|
protected function fixupArrayDestructuring(Array_ $node): Expr\List_ {
|
||||||
$this->createdArrays->detach($node);
|
$this->createdArrays->detach($node);
|
||||||
return new Expr\List_(array_map(function (ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem $item) {
|
return new Expr\List_(array_map(function (Node\ArrayItem $item) {
|
||||||
if ($item->value instanceof Expr\Error) {
|
if ($item->value instanceof Expr\Error) {
|
||||||
// We used Error as a placeholder for empty elements, which are legal for destructuring.
|
// We used Error as a placeholder for empty elements, which are legal for destructuring.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($item->value instanceof Array_) {
|
if ($item->value instanceof Array_) {
|
||||||
return new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem(
|
return new Node\ArrayItem(
|
||||||
$this->fixupArrayDestructuring($item->value),
|
$this->fixupArrayDestructuring($item->value),
|
||||||
$item->key, $item->byRef, $item->getAttributes());
|
$item->key, $item->byRef, $item->getAttributes());
|
||||||
}
|
}
|
||||||
|
@ -1196,7 +1196,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @param array<ncc\ThirdParty\nikic\PhpParser\Node\Arg|ncc\ThirdParty\nikic\PhpParser\Node\VariadicPlaceholder> $args */
|
/** @param array<Node\Arg|Node\VariadicPlaceholder> $args */
|
||||||
private function isSimpleExit(array $args): bool {
|
private function isSimpleExit(array $args): bool {
|
||||||
if (\count($args) === 0) {
|
if (\count($args) === 0) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1210,7 +1210,7 @@ abstract class ParserAbstract implements Parser {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<ncc\ThirdParty\nikic\PhpParser\Node\Arg|ncc\ThirdParty\nikic\PhpParser\Node\VariadicPlaceholder> $args
|
* @param array<Node\Arg|Node\VariadicPlaceholder> $args
|
||||||
* @param array<string, mixed> $attrs
|
* @param array<string, mixed> $attrs
|
||||||
*/
|
*/
|
||||||
protected function createExitExpr(string $name, int $namePos, array $args, array $attrs): Expr {
|
protected function createExitExpr(string $name, int $namePos, array $args, array $attrs): Expr {
|
||||||
|
|
|
@ -815,12 +815,12 @@ class Standard extends PrettyPrinterAbstract {
|
||||||
: ' {' . $this->pStmts($node->adaptations) . $this->nl . '}');
|
: ' {' . $this->pStmts($node->adaptations) . $this->nl . '}');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function pStmt_TraitUseAdaptation_Precedence(\ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence $node): string {
|
protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node): string {
|
||||||
return $this->p($node->trait) . '::' . $node->method
|
return $this->p($node->trait) . '::' . $node->method
|
||||||
. ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
|
. ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function pStmt_TraitUseAdaptation_Alias(\ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Alias $node): string {
|
protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node): string {
|
||||||
return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
|
return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
|
||||||
. $node->method . ' as'
|
. $node->method . ' as'
|
||||||
. (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
|
. (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
|
||||||
|
|
|
@ -122,7 +122,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
|
|
||||||
/** @var TokenStream|null Original tokens for use in format-preserving pretty print */
|
/** @var TokenStream|null Original tokens for use in format-preserving pretty print */
|
||||||
protected ?TokenStream $origTokens;
|
protected ?TokenStream $origTokens;
|
||||||
/** @var ncc\ThirdParty\nikic\PhpParser\Internal\Differ<Node> Differ for node lists */
|
/** @var Internal\Differ<Node> Differ for node lists */
|
||||||
protected Differ $nodeListDiffer;
|
protected Differ $nodeListDiffer;
|
||||||
/** @var array<string, bool> Map determining whether a certain character is a label character */
|
/** @var array<string, bool> Map determining whether a certain character is a label character */
|
||||||
protected array $labelCharMap;
|
protected array $labelCharMap;
|
||||||
|
@ -1069,7 +1069,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::FIXUP_ENCAPSED:
|
case self::FIXUP_ENCAPSED:
|
||||||
if (!$subNode instanceof ncc\ThirdParty\nikic\PhpParser\Node\InterpolatedStringPart
|
if (!$subNode instanceof Node\InterpolatedStringPart
|
||||||
&& !$this->origTokens->haveBraces($subStartPos, $subEndPos)
|
&& !$this->origTokens->haveBraces($subStartPos, $subEndPos)
|
||||||
) {
|
) {
|
||||||
return '{' . $this->p($subNode) . '}';
|
return '{' . $this->p($subNode) . '}';
|
||||||
|
@ -1115,7 +1115,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
* @return bool Whether parentheses are required
|
* @return bool Whether parentheses are required
|
||||||
*/
|
*/
|
||||||
protected function callLhsRequiresParens(Node $node): bool {
|
protected function callLhsRequiresParens(Node $node): bool {
|
||||||
return !($node instanceof ncc\ThirdParty\nikic\PhpParser\Node\Name
|
return !($node instanceof Node\Name
|
||||||
|| $node instanceof Expr\Variable
|
|| $node instanceof Expr\Variable
|
||||||
|| $node instanceof Expr\ArrayDimFetch
|
|| $node instanceof Expr\ArrayDimFetch
|
||||||
|| $node instanceof Expr\FuncCall
|
|| $node instanceof Expr\FuncCall
|
||||||
|
@ -1147,7 +1147,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
*/
|
*/
|
||||||
protected function staticDereferenceLhsRequiresParens(Node $node): bool {
|
protected function staticDereferenceLhsRequiresParens(Node $node): bool {
|
||||||
return !($node instanceof Expr\Variable
|
return !($node instanceof Expr\Variable
|
||||||
|| $node instanceof ncc\ThirdParty\nikic\PhpParser\Node\Name
|
|| $node instanceof Node\Name
|
||||||
|| $node instanceof Expr\ArrayDimFetch
|
|| $node instanceof Expr\ArrayDimFetch
|
||||||
|| $node instanceof Expr\PropertyFetch
|
|| $node instanceof Expr\PropertyFetch
|
||||||
|| $node instanceof Expr\NullsafePropertyFetch
|
|| $node instanceof Expr\NullsafePropertyFetch
|
||||||
|
@ -1169,7 +1169,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
* @return bool Whether parentheses are required
|
* @return bool Whether parentheses are required
|
||||||
*/
|
*/
|
||||||
protected function newOperandRequiresParens(Node $node): bool {
|
protected function newOperandRequiresParens(Node $node): bool {
|
||||||
if ($node instanceof ncc\ThirdParty\nikic\PhpParser\Node\Name || $node instanceof Expr\Variable) {
|
if ($node instanceof Node\Name || $node instanceof Expr\Variable) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch ||
|
if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch ||
|
||||||
|
@ -1272,7 +1272,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->nodeListDiffer = new ncc\ThirdParty\nikic\PhpParser\Internal\Differ(function ($a, $b) {
|
$this->nodeListDiffer = new Internal\Differ(function ($a, $b) {
|
||||||
if ($a instanceof Node && $b instanceof Node) {
|
if ($a instanceof Node && $b instanceof Node) {
|
||||||
return $a === $b->getAttribute('origNode');
|
return $a === $b->getAttribute('origNode');
|
||||||
}
|
}
|
||||||
|
@ -1516,7 +1516,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
|
||||||
Stmt\Property::class . '->props' => ', ',
|
Stmt\Property::class . '->props' => ', ',
|
||||||
Stmt\StaticVar::class . '->vars' => ', ',
|
Stmt\StaticVar::class . '->vars' => ', ',
|
||||||
Stmt\TraitUse::class . '->traits' => ', ',
|
Stmt\TraitUse::class . '->traits' => ', ',
|
||||||
\ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ',
|
Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ',
|
||||||
Stmt\Unset_::class . '->vars' => ', ',
|
Stmt\Unset_::class . '->vars' => ', ',
|
||||||
Stmt\UseUse::class . '->uses' => ', ',
|
Stmt\UseUse::class . '->uses' => ', ',
|
||||||
MatchArm::class . '->conds' => ', ',
|
MatchArm::class . '->conds' => ', ',
|
||||||
|
|
2
src/ncc/ThirdParty/nikic/PhpParser/Token.php
vendored
2
src/ncc/ThirdParty/nikic/PhpParser/Token.php
vendored
|
@ -5,7 +5,7 @@ namespace ncc\ThirdParty\nikic\PhpParser;
|
||||||
/**
|
/**
|
||||||
* A PHP token. On PHP 8.0 this extends from PhpToken.
|
* A PHP token. On PHP 8.0 this extends from PhpToken.
|
||||||
*/
|
*/
|
||||||
class Token extends ncc\ThirdParty\nikic\PhpParser\Internal\TokenPolyfill {
|
class Token extends Internal\TokenPolyfill {
|
||||||
/** Get (exclusive) zero-based end position of the token. */
|
/** Get (exclusive) zero-based end position of the token. */
|
||||||
public function getEndPos(): int {
|
public function getEndPos(): int {
|
||||||
return $this->pos + \strlen($this->text);
|
return $this->pos + \strlen($this->text);
|
||||||
|
|
Loading…
Add table
Reference in a new issue