diff --git a/src/ncc/Classes/PhpExtension/AstWalker.php b/src/ncc/Classes/PhpExtension/AstWalker.php index 8e2f890..282c3d1 100644 --- a/src/ncc/Classes/PhpExtension/AstWalker.php +++ b/src/ncc/Classes/PhpExtension/AstWalker.php @@ -31,27 +31,6 @@ 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 * @@ -112,161 +91,4 @@ 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); - } } \ No newline at end of file diff --git a/src/ncc/Classes/PhpExtension/NccCompiler.php b/src/ncc/Classes/PhpExtension/NccCompiler.php index 0101dd9..603cbed 100644 --- a/src/ncc/Classes/PhpExtension/NccCompiler.php +++ b/src/ncc/Classes/PhpExtension/NccCompiler.php @@ -30,7 +30,9 @@ use ncc\Exceptions\PathNotFoundException; use ncc\Extensions\ZiProto\ZiProto; use ncc\Objects\Package\Component; + use ncc\ThirdParty\nikic\PhpParser\NodeDumper; use ncc\ThirdParty\nikic\PhpParser\ParserFactory; + use ncc\ThirdParty\nikic\PhpParser\PhpVersion; use ncc\Utilities\Base64; use ncc\Utilities\Console; use ncc\Utilities\Functions; @@ -52,12 +54,8 @@ try { - $stmts = (new ParserFactory())->create(ParserFactory::PREFER_PHP7)->parse(IO::fread($file_path)); - $stmts = AstWalker::transformRequireCalls( - $stmts, $this->getProjectManager()->getProjectConfiguration()->getAssembly()->getPackage() - ); - - $component = new Component($component_name, ZiProto::encode($stmts), ComponentDataType::AST); + $stmts = ((new ParserFactory())->createForNewestSupportedVersion())->parse(IO::fread($file_path)); + $component = new Component($component_name, ZiProto::encode(Serializer::nodesToArray($stmts)), ComponentDataType::AST); $component->addFlag(ComponentFlags::PHP_AST->value); $pointer = $package_writer->addComponent($component); diff --git a/src/ncc/Classes/PhpExtension/Serializer.php b/src/ncc/Classes/PhpExtension/Serializer.php new file mode 100644 index 0000000..d4f92a1 --- /dev/null +++ b/src/ncc/Classes/PhpExtension/Serializer.php @@ -0,0 +1,151 @@ +[] 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 */ + 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\""); + } +} \ No newline at end of file diff --git a/src/ncc/Classes/Runtime.php b/src/ncc/Classes/Runtime.php index a324a2d..f5bf8c1 100644 --- a/src/ncc/Classes/Runtime.php +++ b/src/ncc/Classes/Runtime.php @@ -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)); } /** diff --git a/src/ncc/Objects/Package/Component.php b/src/ncc/Objects/Package/Component.php index d44dcc7..8411f73 100644 --- a/src/ncc/Objects/Package/Component.php +++ b/src/ncc/Objects/Package/Component.php @@ -27,6 +27,7 @@ use Exception; use InvalidArgumentException; use ncc\Classes\PhpExtension\AstWalker; + use ncc\Classes\PhpExtension\Serializer; use ncc\Enums\Flags\ComponentFlags; use ncc\Enums\LogLevel; use ncc\Enums\Options\ComponentDecodeOptions; @@ -177,12 +178,15 @@ { try { + $decodedData = base64_decode($this->data); + $ast = Serializer::arrayToNodes((array)$decodedData); + 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) { @@ -197,12 +201,15 @@ { try { + $decodedData = ZiProto::decode($this->data); + $ast = Serializer::arrayToNodes($decodedData); + 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) { diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/ClassConst.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/ClassConst.php index 3beab31..37d0c81 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/ClassConst.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/ClassConst.php @@ -7,10 +7,10 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; use PhpParser\Modifiers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Const_; -use ncc\ThirdParty\nikic\PhpParser\Node\Identifier; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Const_; +use PhpParser\Node\Identifier; +use PhpParser\Node\Stmt; class ClassConst implements PhpParser\Builder { protected int $flags = 0; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Class_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Class_.php index 40f598f..d5b7c67 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Class_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Class_.php @@ -5,9 +5,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; use PhpParser\Modifiers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Name; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt; class Class_ extends Declaration { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Declaration.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Declaration.php index f4bd12e..1377017 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Declaration.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Declaration.php @@ -12,7 +12,7 @@ abstract class Declaration implements PhpParser\Builder { /** * 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) */ @@ -21,7 +21,7 @@ abstract class Declaration implements PhpParser\Builder { /** * 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) */ diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/EnumCase.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/EnumCase.php index 991f586..39005cb 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/EnumCase.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/EnumCase.php @@ -6,9 +6,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Identifier; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Identifier; +use PhpParser\Node\Stmt; class EnumCase implements PhpParser\Builder { /** @var Identifier|string */ diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Enum_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Enum_.php index 3db67e5..eeb7154 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Enum_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Enum_.php @@ -4,10 +4,10 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Identifier; -use ncc\ThirdParty\nikic\PhpParser\Node\Name; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt; class Enum_ extends Declaration { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Function_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Function_.php index eb63e34..9a4d051 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Function_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Function_.php @@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Stmt; class Function_ extends FunctionLike { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Interface_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Interface_.php index 1696950..44d12b1 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Interface_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Interface_.php @@ -4,9 +4,9 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Name; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt; class Interface_ extends Declaration { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Method.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Method.php index fe74e72..3679777 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Method.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Method.php @@ -5,8 +5,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; use PhpParser\Modifiers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Stmt; class Method extends FunctionLike { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Namespace_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Namespace_.php index 674f860..cc5a7c9 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Namespace_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Namespace_.php @@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Stmt; class Namespace_ extends Declaration { private ?Node\Name $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Param.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Param.php index 9a81866..67069e8 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Param.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Param.php @@ -5,7 +5,7 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; use PhpParser\Modifiers; -use ncc\ThirdParty\nikic\PhpParser\Node; +use PhpParser\Node; class Param implements PhpParser\Builder { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Property.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Property.php index 66d819a..1ccfbd1 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Property.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Property.php @@ -5,11 +5,11 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; use PhpParser\Modifiers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Identifier; -use ncc\ThirdParty\nikic\PhpParser\Node\Name; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; -use ncc\ThirdParty\nikic\PhpParser\Node\ComplexType; +use PhpParser\Node; +use PhpParser\Node\Identifier; +use PhpParser\Node\Name; +use PhpParser\Node\Stmt; +use PhpParser\Node\ComplexType; class Property implements PhpParser\Builder { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/TraitUseAdaptation.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/TraitUseAdaptation.php index 4e181a9..6edc4e4 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/TraitUseAdaptation.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/TraitUseAdaptation.php @@ -135,9 +135,9 @@ class TraitUseAdaptation implements Builder { public function getNode(): Node { switch ($this->type) { 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: - 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: throw new \LogicException('Type of adaptation is not defined'); } diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Trait_.php b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Trait_.php index 03491c4..d0bb060 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Builder/Trait_.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Builder/Trait_.php @@ -4,8 +4,8 @@ namespace ncc\ThirdParty\nikic\PhpParser\Builder; use ncc\ThirdParty\nikic\PhpParser; use PhpParser\BuilderHelpers; -use ncc\ThirdParty\nikic\PhpParser\Node; -use ncc\ThirdParty\nikic\PhpParser\Node\Stmt; +use PhpParser\Node; +use PhpParser\Node\Stmt; class Trait_ extends Declaration { protected string $name; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/BuilderFactory.php b/src/ncc/ThirdParty/nikic/PhpParser/BuilderFactory.php index e4f9f07..c74a9a0 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/BuilderFactory.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/BuilderFactory.php @@ -17,8 +17,8 @@ class BuilderFactory { * @param string|Name $name Name of the attribute * @param array $args Attribute named arguments */ - public function attribute($name, array $args = []): ncc\ThirdParty\nikic\PhpParser\Node\Attribute { - return new ncc\ThirdParty\nikic\PhpParser\Node\Attribute( + public function attribute($name, array $args = []): Node\Attribute { + return new Node\Attribute( BuilderHelpers::normalizeName($name), $this->args($args) ); @@ -27,12 +27,12 @@ class BuilderFactory { /** * 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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Namespace_($name); + public function namespace($name): Builder\Namespace_ { + return new Builder\Namespace_($name); } /** @@ -40,10 +40,10 @@ class BuilderFactory { * * @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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Class_($name); + public function class(string $name): Builder\Class_ { + return new Builder\Class_($name); } /** @@ -51,10 +51,10 @@ class BuilderFactory { * * @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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Interface_($name); + public function interface(string $name): Builder\Interface_ { + return new Builder\Interface_($name); } /** @@ -62,10 +62,10 @@ class BuilderFactory { * * @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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Trait_($name); + public function trait(string $name): Builder\Trait_ { + return new Builder\Trait_($name); } /** @@ -73,38 +73,38 @@ class BuilderFactory { * * @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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Enum_($name); + public function enum(string $name): Builder\Enum_ { + return new Builder\Enum_($name); } /** * 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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\TraitUse(...$traits); + public function useTrait(...$traits): Builder\TraitUse { + return new Builder\TraitUse(...$traits); } /** * Creates a trait use adaptation builder. * - * @param ncc\ThirdParty\nikic\PhpParser\Node\Name|string|null $trait Trait name - * @param ncc\ThirdParty\nikic\PhpParser\Node\Identifier|string $method Method name + * @param Node\Name|string|null $trait Trait 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) { $method = $trait; $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 * - * @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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Method($name); + public function method(string $name): Builder\Method { + return new Builder\Method($name); } /** @@ -123,10 +123,10 @@ class BuilderFactory { * * @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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Param($name); + public function param(string $name): Builder\Param { + return new Builder\Param($name); } /** @@ -134,10 +134,10 @@ class BuilderFactory { * * @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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Property($name); + public function property(string $name): Builder\Property { + return new Builder\Property($name); } /** @@ -145,55 +145,55 @@ class BuilderFactory { * * @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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Function_($name); + public function function(string $name): Builder\Function_ { + return new Builder\Function_($name); } /** * 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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_NORMAL); + public function use($name): Builder\Use_ { + return new Builder\Use_($name, Use_::TYPE_NORMAL); } /** * 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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_FUNCTION); + public function useFunction($name): Builder\Use_ { + return new Builder\Use_($name, Use_::TYPE_FUNCTION); } /** * 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_ { - return new ncc\ThirdParty\nikic\PhpParser\Builder\Use_($name, Use_::TYPE_CONSTANT); + public function useConst($name): Builder\Use_ { + return new Builder\Use_($name, Use_::TYPE_CONSTANT); } /** * Creates a class constant builder. * * @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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\ClassConst($name, $value); + public function classConst($name, $value): Builder\ClassConst { + return new Builder\ClassConst($name, $value); } /** @@ -201,10 +201,10 @@ class BuilderFactory { * * @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 { - return new ncc\ThirdParty\nikic\PhpParser\Builder\EnumCase($name); + public function enumCase($name): Builder\EnumCase { + return new Builder\EnumCase($name); } /** diff --git a/src/ncc/ThirdParty/nikic/PhpParser/BuilderHelpers.php b/src/ncc/ThirdParty/nikic/PhpParser/BuilderHelpers.php index cd56a69..cb6c18c 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/BuilderHelpers.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/BuilderHelpers.php @@ -215,12 +215,12 @@ final class BuilderHelpers { * Normalizes a value: Converts nulls, booleans, integers, * 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 */ public static function normalizeValue($value): Expr { - if ($value instanceof ncc\ThirdParty\nikic\PhpParser\Node\Expr) { + if ($value instanceof Node\Expr) { return $value; } @@ -254,12 +254,12 @@ final class BuilderHelpers { foreach ($value as $itemKey => $itemValue) { // for consecutive, numeric keys don't generate keys if (null !== $lastKey && ++$lastKey === $itemKey) { - $items[] = new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem( + $items[] = new Node\ArrayItem( self::normalizeValue($itemValue) ); } else { $lastKey = null; - $items[] = new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem( + $items[] = new Node\ArrayItem( self::normalizeValue($itemValue), self::normalizeValue($itemKey) ); @@ -298,20 +298,20 @@ final class BuilderHelpers { /** * 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 { - if ($attribute instanceof ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup) { + public static function normalizeAttribute($attribute): Node\AttributeGroup { + if ($attribute instanceof Node\AttributeGroup) { 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'); } - return new ncc\ThirdParty\nikic\PhpParser\Node\AttributeGroup([$attribute]); + return new Node\AttributeGroup([$attribute]); } /** diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Internal/TokenPolyfill.php b/src/ncc/ThirdParty/nikic/PhpParser/Internal/TokenPolyfill.php index 256cd8e..1d8e1cf 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Internal/TokenPolyfill.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Internal/TokenPolyfill.php @@ -3,8 +3,7 @@ namespace ncc\ThirdParty\nikic\PhpParser\Internal; if (\PHP_VERSION_ID >= 80000) { - class TokenPolyfill extends \PhpToken { - } + class_alias(\PhpToken::class, TokenPolyfill::class); return; } diff --git a/src/ncc/ThirdParty/nikic/PhpParser/NodeTraverser.php b/src/ncc/ThirdParty/nikic/PhpParser/NodeTraverser.php index 3fc2c19..be5a1f5 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/NodeTraverser.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/NodeTraverser.php @@ -260,7 +260,7 @@ class NodeTraverser implements NodeTraverserInterface { } 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( "Trying to replace statement ({$old->getType()}) " . "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( "Trying to replace expression ({$old->getType()}) " . "with statement ({$new->getType()})" diff --git a/src/ncc/ThirdParty/nikic/PhpParser/NodeVisitor/NameResolver.php b/src/ncc/ThirdParty/nikic/PhpParser/NodeVisitor/NameResolver.php index 55f0837..7d85aaf 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/NodeVisitor/NameResolver.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/NodeVisitor/NameResolver.php @@ -156,7 +156,7 @@ class NameResolver extends NodeVisitorAbstract { $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) { $insteadof = $this->resolveClassName($insteadof); } diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Parser.php b/src/ncc/ThirdParty/nikic/PhpParser/Parser.php index 7e77e49..48593b2 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Parser.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Parser.php @@ -10,7 +10,7 @@ interface Parser { * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults * 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). */ public function parse(string $code, ?ErrorHandler $errorHandler = null): ?array; diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php7.php b/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php7.php index aeae506..2dd32fa 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php7.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php7.php @@ -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)]; }, 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) { - $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) { - $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) { - $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) { - $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) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php8.php b/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php8.php index cf23196..89694a1 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php8.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Parser/Php8.php @@ -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)]; }, 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) { - $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) { - $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) { - $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) { - $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) { $self->semValue = array($self->semStack[$stackPos-(3-1)], $self->semStack[$stackPos-(3-3)]); diff --git a/src/ncc/ThirdParty/nikic/PhpParser/ParserAbstract.php b/src/ncc/ThirdParty/nikic/PhpParser/ParserAbstract.php index c83c715..4ef6768 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/ParserAbstract.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/ParserAbstract.php @@ -174,7 +174,7 @@ abstract class ParserAbstract implements Parser { * @param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults * 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). */ 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. * - * @param ncc\ThirdParty\nikic\PhpParser\Node\Stmt[] $stmts - * @return ncc\ThirdParty\nikic\PhpParser\Node\Stmt[] + * @param Node\Stmt[] $stmts + * @return Node\Stmt[] */ protected function handleNamespaces(array $stmts): array { $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 $afterFirstNamespace = false; foreach ($stmts as $stmt) { - if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_) { + if ($stmt instanceof Node\Stmt\Namespace_) { $afterFirstNamespace = true; - } elseif (!$stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\HaltCompiler - && !$stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Nop + } elseif (!$stmt instanceof Node\Stmt\HaltCompiler + && !$stmt instanceof Node\Stmt\Nop && $afterFirstNamespace && !$hasErrored) { $this->emitError(new Error( 'No code may exist outside of namespace {}', $stmt->getAttributes())); @@ -586,7 +586,7 @@ abstract class ParserAbstract implements Parser { $targetStmts = &$resultStmts; $lastNs = null; foreach ($stmts as $stmt) { - if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Namespace_) { + if ($stmt instanceof Node\Stmt\Namespace_) { if ($lastNs !== null) { $this->fixupNamespaceAttributes($lastNs); } @@ -600,7 +600,7 @@ abstract class ParserAbstract implements Parser { $targetStmts = &$resultStmts; } $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 $resultStmts[] = $stmt; } 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 // needs to be extended to the end of the statements. if (empty($stmt->stmts)) { @@ -659,7 +659,7 @@ abstract class ParserAbstract implements Parser { $style = null; $hasNotAllowedStmts = false; 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'; if (null === $style) { $style = $currentStyle; @@ -681,14 +681,14 @@ abstract class ParserAbstract implements Parser { } /* declare(), __halt_compiler() and nops can be used before a namespace declaration */ - if ($stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Declare_ - || $stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\HaltCompiler - || $stmt instanceof ncc\ThirdParty\nikic\PhpParser\Node\Stmt\Nop) { + if ($stmt instanceof Node\Stmt\Declare_ + || $stmt instanceof Node\Stmt\HaltCompiler + || $stmt instanceof Node\Stmt\Nop) { continue; } /* 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; } @@ -709,7 +709,7 @@ abstract class ParserAbstract implements Parser { 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); } else { 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 $this->stripIndentation( '', $indentLen, $indentChar, true, false, $contents[0]->getAttributes() @@ -869,7 +869,7 @@ abstract class ParserAbstract implements Parser { $newContents = []; foreach ($contents as $i => $part) { - if ($part instanceof ncc\ThirdParty\nikic\PhpParser\Node\InterpolatedStringPart) { + if ($part instanceof Node\InterpolatedStringPart) { $isLast = $i === \count($contents) - 1; $part->value = $this->stripIndentation( $part->value, $indentLen, $indentChar, @@ -977,13 +977,13 @@ abstract class ParserAbstract implements Parser { protected function fixupArrayDestructuring(Array_ $node): Expr\List_ { $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) { // We used Error as a placeholder for empty elements, which are legal for destructuring. return null; } if ($item->value instanceof Array_) { - return new ncc\ThirdParty\nikic\PhpParser\Node\ArrayItem( + return new Node\ArrayItem( $this->fixupArrayDestructuring($item->value), $item->key, $item->byRef, $item->getAttributes()); } @@ -1196,7 +1196,7 @@ abstract class ParserAbstract implements Parser { } } - /** @param array $args */ + /** @param array $args */ private function isSimpleExit(array $args): bool { if (\count($args) === 0) { return true; @@ -1210,7 +1210,7 @@ abstract class ParserAbstract implements Parser { } /** - * @param array $args + * @param array $args * @param array $attrs */ protected function createExitExpr(string $name, int $namePos, array $args, array $attrs): Expr { diff --git a/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinter/Standard.php b/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinter/Standard.php index be11404..7fe32b6 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinter/Standard.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinter/Standard.php @@ -815,12 +815,12 @@ class Standard extends PrettyPrinterAbstract { : ' {' . $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 . ' 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) . '::' : '') . $node->method . ' as' . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') diff --git a/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinterAbstract.php b/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinterAbstract.php index 43fe1a9..b5c433a 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinterAbstract.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/PrettyPrinterAbstract.php @@ -122,7 +122,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { /** @var TokenStream|null Original tokens for use in format-preserving pretty print */ protected ?TokenStream $origTokens; - /** @var ncc\ThirdParty\nikic\PhpParser\Internal\Differ Differ for node lists */ + /** @var Internal\Differ Differ for node lists */ protected Differ $nodeListDiffer; /** @var array Map determining whether a certain character is a label character */ protected array $labelCharMap; @@ -1069,7 +1069,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { } break; case self::FIXUP_ENCAPSED: - if (!$subNode instanceof ncc\ThirdParty\nikic\PhpParser\Node\InterpolatedStringPart + if (!$subNode instanceof Node\InterpolatedStringPart && !$this->origTokens->haveBraces($subStartPos, $subEndPos) ) { return '{' . $this->p($subNode) . '}'; @@ -1115,7 +1115,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { * @return bool Whether parentheses are required */ 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\ArrayDimFetch || $node instanceof Expr\FuncCall @@ -1147,7 +1147,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { */ protected function staticDereferenceLhsRequiresParens(Node $node): bool { return !($node instanceof Expr\Variable - || $node instanceof ncc\ThirdParty\nikic\PhpParser\Node\Name + || $node instanceof Node\Name || $node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || $node instanceof Expr\NullsafePropertyFetch @@ -1169,7 +1169,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { * @return bool Whether parentheses are required */ 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; } if ($node instanceof Expr\ArrayDimFetch || $node instanceof Expr\PropertyFetch || @@ -1272,7 +1272,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { 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) { return $a === $b->getAttribute('origNode'); } @@ -1516,7 +1516,7 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter { Stmt\Property::class . '->props' => ', ', Stmt\StaticVar::class . '->vars' => ', ', Stmt\TraitUse::class . '->traits' => ', ', - \ncc\ThirdParty\nikic\PhpParser\Node\Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ', + Stmt\TraitUseAdaptation\Precedence::class . '->insteadof' => ', ', Stmt\Unset_::class . '->vars' => ', ', Stmt\UseUse::class . '->uses' => ', ', MatchArm::class . '->conds' => ', ', diff --git a/src/ncc/ThirdParty/nikic/PhpParser/Token.php b/src/ncc/ThirdParty/nikic/PhpParser/Token.php index bab630d..221e415 100644 --- a/src/ncc/ThirdParty/nikic/PhpParser/Token.php +++ b/src/ncc/ThirdParty/nikic/PhpParser/Token.php @@ -5,7 +5,7 @@ namespace ncc\ThirdParty\nikic\PhpParser; /** * 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. */ public function getEndPos(): int { return $this->pos + \strlen($this->text);