Composer updates
This commit is contained in:
34
vendor/phpstan/phpdoc-parser/src/Ast/AbstractNodeVisitor.php
vendored
Normal file
34
vendor/phpstan/phpdoc-parser/src/Ast/AbstractNodeVisitor.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast;
|
||||
|
||||
/**
|
||||
* Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1
|
||||
*
|
||||
* Copyright (c) 2011, Nikita Popov
|
||||
* All rights reserved.
|
||||
*/
|
||||
abstract class AbstractNodeVisitor implements NodeVisitor
|
||||
{
|
||||
|
||||
public function beforeTraverse(array $nodes): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function afterTraverse(array $nodes): ?array
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
16
vendor/phpstan/phpdoc-parser/src/Ast/Attribute.php
vendored
Normal file
16
vendor/phpstan/phpdoc-parser/src/Ast/Attribute.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast;
|
||||
|
||||
final class Attribute
|
||||
{
|
||||
|
||||
public const START_LINE = 'startLine';
|
||||
public const END_LINE = 'endLine';
|
||||
|
||||
public const START_INDEX = 'startIndex';
|
||||
public const END_INDEX = 'endIndex';
|
||||
|
||||
public const ORIGINAL_NODE = 'originalNode';
|
||||
|
||||
}
|
||||
78
vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/QuoteAwareConstExprStringNode.php
vendored
Normal file
78
vendor/phpstan/phpdoc-parser/src/Ast/ConstExpr/QuoteAwareConstExprStringNode.php
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use function addcslashes;
|
||||
use function assert;
|
||||
use function dechex;
|
||||
use function ord;
|
||||
use function preg_replace_callback;
|
||||
use function sprintf;
|
||||
use function str_pad;
|
||||
use function strlen;
|
||||
use const STR_PAD_LEFT;
|
||||
|
||||
class QuoteAwareConstExprStringNode extends ConstExprStringNode implements ConstExprNode
|
||||
{
|
||||
|
||||
public const SINGLE_QUOTED = 1;
|
||||
public const DOUBLE_QUOTED = 2;
|
||||
|
||||
use NodeAttributes;
|
||||
|
||||
/** @var self::SINGLE_QUOTED|self::DOUBLE_QUOTED */
|
||||
public $quoteType;
|
||||
|
||||
/**
|
||||
* @param self::SINGLE_QUOTED|self::DOUBLE_QUOTED $quoteType
|
||||
*/
|
||||
public function __construct(string $value, int $quoteType)
|
||||
{
|
||||
parent::__construct($value);
|
||||
$this->quoteType = $quoteType;
|
||||
}
|
||||
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if ($this->quoteType === self::SINGLE_QUOTED) {
|
||||
// from https://github.com/nikic/PHP-Parser/blob/0ffddce52d816f72d0efc4d9b02e276d3309ef01/lib/PhpParser/PrettyPrinter/Standard.php#L1007
|
||||
return sprintf("'%s'", addcslashes($this->value, '\'\\'));
|
||||
}
|
||||
|
||||
// from https://github.com/nikic/PHP-Parser/blob/0ffddce52d816f72d0efc4d9b02e276d3309ef01/lib/PhpParser/PrettyPrinter/Standard.php#L1010-L1040
|
||||
return sprintf('"%s"', $this->escapeDoubleQuotedString());
|
||||
}
|
||||
|
||||
private function escapeDoubleQuotedString(): string
|
||||
{
|
||||
$quote = '"';
|
||||
$escaped = addcslashes($this->value, "\n\r\t\f\v$" . $quote . '\\');
|
||||
|
||||
// Escape control characters and non-UTF-8 characters.
|
||||
// Regex based on https://stackoverflow.com/a/11709412/385378.
|
||||
$regex = '/(
|
||||
[\x00-\x08\x0E-\x1F] # Control characters
|
||||
| [\xC0-\xC1] # Invalid UTF-8 Bytes
|
||||
| [\xF5-\xFF] # Invalid UTF-8 Bytes
|
||||
| \xE0(?=[\x80-\x9F]) # Overlong encoding of prior code point
|
||||
| \xF0(?=[\x80-\x8F]) # Overlong encoding of prior code point
|
||||
| [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start
|
||||
| [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start
|
||||
| [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start
|
||||
| (?<=[\x00-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle
|
||||
| (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4]|[\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence
|
||||
| (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence
|
||||
| (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
|
||||
| (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
|
||||
)/x';
|
||||
return preg_replace_callback($regex, static function ($matches) {
|
||||
assert(strlen($matches[0]) === 1);
|
||||
$hex = dechex(ord($matches[0]));
|
||||
|
||||
return '\\x' . str_pad($hex, 2, '0', STR_PAD_LEFT);
|
||||
}, $escaped);
|
||||
}
|
||||
|
||||
}
|
||||
312
vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
vendored
Normal file
312
vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
vendored
Normal file
@@ -0,0 +1,312 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast;
|
||||
|
||||
use LogicException;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
|
||||
use function array_keys;
|
||||
use function array_pop;
|
||||
use function array_splice;
|
||||
use function count;
|
||||
use function get_class;
|
||||
use function get_object_vars;
|
||||
use function gettype;
|
||||
use function is_array;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
* Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1
|
||||
*
|
||||
* Copyright (c) 2011, Nikita Popov
|
||||
* All rights reserved.
|
||||
*/
|
||||
final class NodeTraverser
|
||||
{
|
||||
|
||||
/**
|
||||
* If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes
|
||||
* of the current node will not be traversed for any visitors.
|
||||
*
|
||||
* For subsequent visitors enterNode() will still be called on the current
|
||||
* node and leaveNode() will also be invoked for the current node.
|
||||
*/
|
||||
public const DONT_TRAVERSE_CHILDREN = 1;
|
||||
|
||||
/**
|
||||
* If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns
|
||||
* STOP_TRAVERSAL, traversal is aborted.
|
||||
*
|
||||
* The afterTraverse() method will still be invoked.
|
||||
*/
|
||||
public const STOP_TRAVERSAL = 2;
|
||||
|
||||
/**
|
||||
* If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs
|
||||
* in an array, it will be removed from the array.
|
||||
*
|
||||
* For subsequent visitors leaveNode() will still be invoked for the
|
||||
* removed node.
|
||||
*/
|
||||
public const REMOVE_NODE = 3;
|
||||
|
||||
/**
|
||||
* If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes
|
||||
* of the current node will not be traversed for any visitors.
|
||||
*
|
||||
* For subsequent visitors enterNode() will not be called as well.
|
||||
* leaveNode() will be invoked for visitors that has enterNode() method invoked.
|
||||
*/
|
||||
public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4;
|
||||
|
||||
/** @var list<NodeVisitor> Visitors */
|
||||
private $visitors = [];
|
||||
|
||||
/** @var bool Whether traversal should be stopped */
|
||||
private $stopTraversal;
|
||||
|
||||
/**
|
||||
* @param list<NodeVisitor> $visitors
|
||||
*/
|
||||
public function __construct(array $visitors)
|
||||
{
|
||||
$this->visitors = $visitors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traverses an array of nodes using the registered visitors.
|
||||
*
|
||||
* @param Node[] $nodes Array of nodes
|
||||
*
|
||||
* @return Node[] Traversed array of nodes
|
||||
*/
|
||||
public function traverse(array $nodes): array
|
||||
{
|
||||
$this->stopTraversal = false;
|
||||
|
||||
foreach ($this->visitors as $visitor) {
|
||||
$return = $visitor->beforeTraverse($nodes);
|
||||
if ($return === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$nodes = $return;
|
||||
}
|
||||
|
||||
$nodes = $this->traverseArray($nodes);
|
||||
|
||||
foreach ($this->visitors as $visitor) {
|
||||
$return = $visitor->afterTraverse($nodes);
|
||||
if ($return === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$nodes = $return;
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively traverse a node.
|
||||
*
|
||||
* @param Node $node Node to traverse.
|
||||
*
|
||||
* @return Node Result of traversal (may be original node or new one)
|
||||
*/
|
||||
private function traverseNode(Node $node): Node
|
||||
{
|
||||
$subNodeNames = array_keys(get_object_vars($node));
|
||||
foreach ($subNodeNames as $name) {
|
||||
$subNode =& $node->$name;
|
||||
|
||||
if (is_array($subNode)) {
|
||||
$subNode = $this->traverseArray($subNode);
|
||||
if ($this->stopTraversal) {
|
||||
break;
|
||||
}
|
||||
} elseif ($subNode instanceof Node) {
|
||||
$traverseChildren = true;
|
||||
$breakVisitorIndex = null;
|
||||
|
||||
foreach ($this->visitors as $visitorIndex => $visitor) {
|
||||
$return = $visitor->enterNode($subNode);
|
||||
if ($return === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($return instanceof Node) {
|
||||
$this->ensureReplacementReasonable($subNode, $return);
|
||||
$subNode = $return;
|
||||
} elseif ($return === self::DONT_TRAVERSE_CHILDREN) {
|
||||
$traverseChildren = false;
|
||||
} elseif ($return === self::DONT_TRAVERSE_CURRENT_AND_CHILDREN) {
|
||||
$traverseChildren = false;
|
||||
$breakVisitorIndex = $visitorIndex;
|
||||
break;
|
||||
} elseif ($return === self::STOP_TRAVERSAL) {
|
||||
$this->stopTraversal = true;
|
||||
break 2;
|
||||
} else {
|
||||
throw new LogicException(
|
||||
'enterNode() returned invalid value of type ' . gettype($return)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($traverseChildren) {
|
||||
$subNode = $this->traverseNode($subNode);
|
||||
if ($this->stopTraversal) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->visitors as $visitorIndex => $visitor) {
|
||||
$return = $visitor->leaveNode($subNode);
|
||||
|
||||
if ($return !== null) {
|
||||
if ($return instanceof Node) {
|
||||
$this->ensureReplacementReasonable($subNode, $return);
|
||||
$subNode = $return;
|
||||
} elseif ($return === self::STOP_TRAVERSAL) {
|
||||
$this->stopTraversal = true;
|
||||
break 2;
|
||||
} elseif (is_array($return)) {
|
||||
throw new LogicException(
|
||||
'leaveNode() may only return an array ' .
|
||||
'if the parent structure is an array'
|
||||
);
|
||||
} else {
|
||||
throw new LogicException(
|
||||
'leaveNode() returned invalid value of type ' . gettype($return)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($breakVisitorIndex === $visitorIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively traverse array (usually of nodes).
|
||||
*
|
||||
* @param mixed[] $nodes Array to traverse
|
||||
*
|
||||
* @return mixed[] Result of traversal (may be original array or changed one)
|
||||
*/
|
||||
private function traverseArray(array $nodes): array
|
||||
{
|
||||
$doNodes = [];
|
||||
|
||||
foreach ($nodes as $i => &$node) {
|
||||
if ($node instanceof Node) {
|
||||
$traverseChildren = true;
|
||||
$breakVisitorIndex = null;
|
||||
|
||||
foreach ($this->visitors as $visitorIndex => $visitor) {
|
||||
$return = $visitor->enterNode($node);
|
||||
if ($return === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($return instanceof Node) {
|
||||
$this->ensureReplacementReasonable($node, $return);
|
||||
$node = $return;
|
||||
} elseif (is_array($return)) {
|
||||
$doNodes[] = [$i, $return];
|
||||
continue 2;
|
||||
} elseif ($return === self::REMOVE_NODE) {
|
||||
$doNodes[] = [$i, []];
|
||||
continue 2;
|
||||
} elseif ($return === self::DONT_TRAVERSE_CHILDREN) {
|
||||
$traverseChildren = false;
|
||||
} elseif ($return === self::DONT_TRAVERSE_CURRENT_AND_CHILDREN) {
|
||||
$traverseChildren = false;
|
||||
$breakVisitorIndex = $visitorIndex;
|
||||
break;
|
||||
} elseif ($return === self::STOP_TRAVERSAL) {
|
||||
$this->stopTraversal = true;
|
||||
break 2;
|
||||
} else {
|
||||
throw new LogicException(
|
||||
'enterNode() returned invalid value of type ' . gettype($return)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($traverseChildren) {
|
||||
$node = $this->traverseNode($node);
|
||||
if ($this->stopTraversal) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->visitors as $visitorIndex => $visitor) {
|
||||
$return = $visitor->leaveNode($node);
|
||||
|
||||
if ($return !== null) {
|
||||
if ($return instanceof Node) {
|
||||
$this->ensureReplacementReasonable($node, $return);
|
||||
$node = $return;
|
||||
} elseif (is_array($return)) {
|
||||
$doNodes[] = [$i, $return];
|
||||
break;
|
||||
} elseif ($return === self::REMOVE_NODE) {
|
||||
$doNodes[] = [$i, []];
|
||||
break;
|
||||
} elseif ($return === self::STOP_TRAVERSAL) {
|
||||
$this->stopTraversal = true;
|
||||
break 2;
|
||||
} else {
|
||||
throw new LogicException(
|
||||
'leaveNode() returned invalid value of type ' . gettype($return)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($breakVisitorIndex === $visitorIndex) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (is_array($node)) {
|
||||
throw new LogicException('Invalid node structure: Contains nested arrays');
|
||||
}
|
||||
}
|
||||
|
||||
if (count($doNodes) > 0) {
|
||||
while ([$i, $replace] = array_pop($doNodes)) {
|
||||
array_splice($nodes, $i, 1, $replace);
|
||||
}
|
||||
}
|
||||
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
private function ensureReplacementReasonable(Node $old, Node $new): void
|
||||
{
|
||||
if ($old instanceof TypeNode && !$new instanceof TypeNode) {
|
||||
throw new LogicException(sprintf('Trying to replace TypeNode with %s', get_class($new)));
|
||||
}
|
||||
|
||||
if ($old instanceof ConstExprNode && !$new instanceof ConstExprNode) {
|
||||
throw new LogicException(sprintf('Trying to replace ConstExprNode with %s', get_class($new)));
|
||||
}
|
||||
|
||||
if ($old instanceof PhpDocChildNode && !$new instanceof PhpDocChildNode) {
|
||||
throw new LogicException(sprintf('Trying to replace PhpDocChildNode with %s', get_class($new)));
|
||||
}
|
||||
|
||||
if ($old instanceof PhpDocTagValueNode && !$new instanceof PhpDocTagValueNode) {
|
||||
throw new LogicException(sprintf('Trying to replace PhpDocTagValueNode with %s', get_class($new)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
87
vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor.php
vendored
Normal file
87
vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor.php
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast;
|
||||
|
||||
/**
|
||||
* Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1
|
||||
*
|
||||
* Copyright (c) 2011, Nikita Popov
|
||||
* All rights reserved.
|
||||
*/
|
||||
interface NodeVisitor
|
||||
{
|
||||
|
||||
/**
|
||||
* Called once before traversal.
|
||||
*
|
||||
* Return value semantics:
|
||||
* * null: $nodes stays as-is
|
||||
* * otherwise: $nodes is set to the return value
|
||||
*
|
||||
* @param Node[] $nodes Array of nodes
|
||||
*
|
||||
* @return Node[]|null Array of nodes
|
||||
*/
|
||||
public function beforeTraverse(array $nodes): ?array;
|
||||
|
||||
/**
|
||||
* Called when entering a node.
|
||||
*
|
||||
* Return value semantics:
|
||||
* * null
|
||||
* => $node stays as-is
|
||||
* * array (of Nodes)
|
||||
* => The return value is merged into the parent array (at the position of the $node)
|
||||
* * NodeTraverser::REMOVE_NODE
|
||||
* => $node is removed from the parent array
|
||||
* * NodeTraverser::DONT_TRAVERSE_CHILDREN
|
||||
* => Children of $node are not traversed. $node stays as-is
|
||||
* * NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN
|
||||
* => Further visitors for the current node are skipped, and its children are not
|
||||
* traversed. $node stays as-is.
|
||||
* * NodeTraverser::STOP_TRAVERSAL
|
||||
* => Traversal is aborted. $node stays as-is
|
||||
* * otherwise
|
||||
* => $node is set to the return value
|
||||
*
|
||||
* @param Node $node Node
|
||||
*
|
||||
* @return Node|Node[]|NodeTraverser::*|null Replacement node (or special return value)
|
||||
*/
|
||||
public function enterNode(Node $node);
|
||||
|
||||
/**
|
||||
* Called when leaving a node.
|
||||
*
|
||||
* Return value semantics:
|
||||
* * null
|
||||
* => $node stays as-is
|
||||
* * NodeTraverser::REMOVE_NODE
|
||||
* => $node is removed from the parent array
|
||||
* * NodeTraverser::STOP_TRAVERSAL
|
||||
* => Traversal is aborted. $node stays as-is
|
||||
* * array (of Nodes)
|
||||
* => The return value is merged into the parent array (at the position of the $node)
|
||||
* * otherwise
|
||||
* => $node is set to the return value
|
||||
*
|
||||
* @param Node $node Node
|
||||
*
|
||||
* @return Node|Node[]|NodeTraverser::REMOVE_NODE|NodeTraverser::STOP_TRAVERSAL|null Replacement node (or special return value)
|
||||
*/
|
||||
public function leaveNode(Node $node);
|
||||
|
||||
/**
|
||||
* Called once after traversal.
|
||||
*
|
||||
* Return value semantics:
|
||||
* * null: $nodes stays as-is
|
||||
* * otherwise: $nodes is set to the return value
|
||||
*
|
||||
* @param Node[] $nodes Array of nodes
|
||||
*
|
||||
* @return Node[]|null Array of nodes
|
||||
*/
|
||||
public function afterTraverse(array $nodes): ?array;
|
||||
|
||||
}
|
||||
20
vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor/CloningVisitor.php
vendored
Normal file
20
vendor/phpstan/phpdoc-parser/src/Ast/NodeVisitor/CloningVisitor.php
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\NodeVisitor;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
|
||||
use PHPStan\PhpDocParser\Ast\Attribute;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
|
||||
final class CloningVisitor extends AbstractNodeVisitor
|
||||
{
|
||||
|
||||
public function enterNode(Node $originalNode)
|
||||
{
|
||||
$node = clone $originalNode;
|
||||
$node->setAttribute(Attribute::ORIGINAL_NODE, $originalNode);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,10 +31,11 @@ class InvalidTagValueNode implements PhpDocTagValueNode
|
||||
$exception->getCurrentOffset(),
|
||||
$exception->getExpectedTokenType(),
|
||||
$exception->getExpectedTokenValue(),
|
||||
$exception->getCurrentTokenLine(),
|
||||
];
|
||||
}
|
||||
|
||||
public function __get(string $name)
|
||||
public function __get(string $name): ?ParserException
|
||||
{
|
||||
if ($name !== 'exception') {
|
||||
trigger_error(sprintf('Undefined property: %s::$%s', self::class, $name), E_USER_WARNING);
|
||||
|
||||
@@ -30,6 +30,10 @@ class MethodTagValueNode implements PhpDocTagValueNode
|
||||
/** @var string (may be empty) */
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* @param MethodTagValueParameterNode[] $parameters
|
||||
* @param TemplateTagValueNode[] $templateTypes
|
||||
*/
|
||||
public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description, array $templateTypes = [])
|
||||
{
|
||||
$this->isStatic = $isStatic;
|
||||
|
||||
@@ -23,6 +23,7 @@ class ArrayShapeNode implements TypeNode
|
||||
public $kind;
|
||||
|
||||
/**
|
||||
* @param ArrayShapeItemNode[] $items
|
||||
* @param self::KIND_* $kind
|
||||
*/
|
||||
public function __construct(array $items, bool $sealed = true, string $kind = self::KIND_ARRAY)
|
||||
|
||||
@@ -20,6 +20,14 @@ class ArrayTypeNode implements TypeNode
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if (
|
||||
$this->type instanceof CallableTypeNode
|
||||
|| $this->type instanceof ConstTypeNode
|
||||
|| $this->type instanceof NullableTypeNode
|
||||
) {
|
||||
return '(' . $this->type . ')[]';
|
||||
}
|
||||
|
||||
return $this->type . '[]';
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ class CallableTypeNode implements TypeNode
|
||||
/** @var TypeNode */
|
||||
public $returnType;
|
||||
|
||||
/**
|
||||
* @param CallableTypeParameterNode[] $parameters
|
||||
*/
|
||||
public function __construct(IdentifierTypeNode $identifier, array $parameters, TypeNode $returnType)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
@@ -29,8 +32,12 @@ class CallableTypeNode implements TypeNode
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
$returnType = $this->returnType;
|
||||
if ($returnType instanceof self) {
|
||||
$returnType = "({$returnType})";
|
||||
}
|
||||
$parameters = implode(', ', $this->parameters);
|
||||
return "{$this->identifier}({$parameters}): {$this->returnType}";
|
||||
return "{$this->identifier}({$parameters}): {$returnType}";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ class CallableTypeParameterNode implements Node
|
||||
$type = "{$this->type} ";
|
||||
$isReference = $this->isReference ? '&' : '';
|
||||
$isVariadic = $this->isVariadic ? '...' : '';
|
||||
$default = $this->isOptional ? ' = default' : '';
|
||||
return trim("{$type}{$isReference}{$isVariadic}{$this->parameterName}") . $default;
|
||||
$isOptional = $this->isOptional ? '=' : '';
|
||||
return trim("{$type}{$isReference}{$isVariadic}{$this->parameterName}") . $isOptional;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ class GenericTypeNode implements TypeNode
|
||||
/** @var (self::VARIANCE_*)[] */
|
||||
public $variances;
|
||||
|
||||
/**
|
||||
* @param TypeNode[] $genericTypes
|
||||
* @param (self::VARIANCE_*)[] $variances
|
||||
*/
|
||||
public function __construct(IdentifierTypeNode $type, array $genericTypes, array $variances = [])
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use function array_map;
|
||||
use function implode;
|
||||
|
||||
class IntersectionTypeNode implements TypeNode
|
||||
@@ -13,6 +14,9 @@ class IntersectionTypeNode implements TypeNode
|
||||
/** @var TypeNode[] */
|
||||
public $types;
|
||||
|
||||
/**
|
||||
* @param TypeNode[] $types
|
||||
*/
|
||||
public function __construct(array $types)
|
||||
{
|
||||
$this->types = $types;
|
||||
@@ -21,7 +25,13 @@ class IntersectionTypeNode implements TypeNode
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return '(' . implode(' & ', $this->types) . ')';
|
||||
return '(' . implode(' & ', array_map(static function (TypeNode $type): string {
|
||||
if ($type instanceof NullableTypeNode) {
|
||||
return '(' . $type . ')';
|
||||
}
|
||||
|
||||
return (string) $type;
|
||||
}, $this->types)) . ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
38
vendor/phpstan/phpdoc-parser/src/Ast/Type/InvalidTypeNode.php
vendored
Normal file
38
vendor/phpstan/phpdoc-parser/src/Ast/Type/InvalidTypeNode.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use PHPStan\PhpDocParser\Parser\ParserException;
|
||||
|
||||
class InvalidTypeNode implements TypeNode
|
||||
{
|
||||
|
||||
use NodeAttributes;
|
||||
|
||||
/** @var mixed[] */
|
||||
private $exceptionArgs;
|
||||
|
||||
public function __construct(ParserException $exception)
|
||||
{
|
||||
$this->exceptionArgs = [
|
||||
$exception->getCurrentTokenValue(),
|
||||
$exception->getCurrentTokenType(),
|
||||
$exception->getCurrentOffset(),
|
||||
$exception->getExpectedTokenType(),
|
||||
$exception->getExpectedTokenValue(),
|
||||
$exception->getCurrentTokenLine(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getException(): ParserException
|
||||
{
|
||||
return new ParserException(...$this->exceptionArgs);
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return '*Invalid type*';
|
||||
}
|
||||
|
||||
}
|
||||
48
vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeItemNode.php
vendored
Normal file
48
vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeItemNode.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use function sprintf;
|
||||
|
||||
class ObjectShapeItemNode implements TypeNode
|
||||
{
|
||||
|
||||
use NodeAttributes;
|
||||
|
||||
/** @var ConstExprStringNode|IdentifierTypeNode */
|
||||
public $keyName;
|
||||
|
||||
/** @var bool */
|
||||
public $optional;
|
||||
|
||||
/** @var TypeNode */
|
||||
public $valueType;
|
||||
|
||||
/**
|
||||
* @param ConstExprStringNode|IdentifierTypeNode $keyName
|
||||
*/
|
||||
public function __construct($keyName, bool $optional, TypeNode $valueType)
|
||||
{
|
||||
$this->keyName = $keyName;
|
||||
$this->optional = $optional;
|
||||
$this->valueType = $valueType;
|
||||
}
|
||||
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if ($this->keyName !== null) {
|
||||
return sprintf(
|
||||
'%s%s: %s',
|
||||
(string) $this->keyName,
|
||||
$this->optional ? '?' : '',
|
||||
(string) $this->valueType
|
||||
);
|
||||
}
|
||||
|
||||
return (string) $this->valueType;
|
||||
}
|
||||
|
||||
}
|
||||
31
vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeNode.php
vendored
Normal file
31
vendor/phpstan/phpdoc-parser/src/Ast/Type/ObjectShapeNode.php
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use function implode;
|
||||
|
||||
class ObjectShapeNode implements TypeNode
|
||||
{
|
||||
|
||||
use NodeAttributes;
|
||||
|
||||
/** @var ObjectShapeItemNode[] */
|
||||
public $items;
|
||||
|
||||
/**
|
||||
* @param ObjectShapeItemNode[] $items
|
||||
*/
|
||||
public function __construct(array $items)
|
||||
{
|
||||
$this->items = $items;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
$items = $this->items;
|
||||
|
||||
return 'object{' . implode(', ', $items) . '}';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,14 @@ class OffsetAccessTypeNode implements TypeNode
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
if (
|
||||
$this->type instanceof CallableTypeNode
|
||||
|| $this->type instanceof ConstTypeNode
|
||||
|| $this->type instanceof NullableTypeNode
|
||||
) {
|
||||
return '(' . $this->type . ')[' . $this->offset . ']';
|
||||
}
|
||||
|
||||
return $this->type . '[' . $this->offset . ']';
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace PHPStan\PhpDocParser\Ast\Type;
|
||||
|
||||
use PHPStan\PhpDocParser\Ast\NodeAttributes;
|
||||
use function array_map;
|
||||
use function implode;
|
||||
|
||||
class UnionTypeNode implements TypeNode
|
||||
@@ -13,6 +14,9 @@ class UnionTypeNode implements TypeNode
|
||||
/** @var TypeNode[] */
|
||||
public $types;
|
||||
|
||||
/**
|
||||
* @param TypeNode[] $types
|
||||
*/
|
||||
public function __construct(array $types)
|
||||
{
|
||||
$this->types = $types;
|
||||
@@ -21,7 +25,13 @@ class UnionTypeNode implements TypeNode
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
return '(' . implode(' | ', $this->types) . ')';
|
||||
return '(' . implode(' | ', array_map(static function (TypeNode $type): string {
|
||||
if ($type instanceof NullableTypeNode) {
|
||||
return '(' . $type . ')';
|
||||
}
|
||||
|
||||
return (string) $type;
|
||||
}, $this->types)) . ')';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user