code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function args(array $args) : array
{
$normalizedArgs = [];
foreach ($args as $key => $arg) {
if (!$arg instanceof Arg) {
$arg = new Arg(BuilderHelpers::normalizeValue($arg));
}
if (\is_string($key)) {
$arg->name = BuilderHelpers::normalizeIdentifier($key);
}
$normalizedArgs[] = $arg;
}
return $normalizedArgs;
}
|
Normalizes an argument list.
Creates Arg nodes for all arguments and converts literal values to expressions.
@param array $args List of arguments to normalize
@return list<Arg>
|
args
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function funcCall($name, array $args = []) : Expr\FuncCall
{
return new Expr\FuncCall(BuilderHelpers::normalizeNameOrExpr($name), $this->args($args));
}
|
Creates a function call node.
@param string|Name|Expr $name Function name
@param array $args Function arguments
|
funcCall
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function methodCall(Expr $var, $name, array $args = []) : Expr\MethodCall
{
return new Expr\MethodCall($var, BuilderHelpers::normalizeIdentifierOrExpr($name), $this->args($args));
}
|
Creates a method call node.
@param Expr $var Variable the method is called on
@param string|Identifier|Expr $name Method name
@param array $args Method arguments
|
methodCall
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function staticCall($class, $name, array $args = []) : Expr\StaticCall
{
return new Expr\StaticCall(BuilderHelpers::normalizeNameOrExpr($class), BuilderHelpers::normalizeIdentifierOrExpr($name), $this->args($args));
}
|
Creates a static method call node.
@param string|Name|Expr $class Class name
@param string|Identifier|Expr $name Method name
@param array $args Method arguments
|
staticCall
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function new($class, array $args = []) : Expr\New_
{
return new Expr\New_(BuilderHelpers::normalizeNameOrExpr($class), $this->args($args));
}
|
Creates an object creation node.
@param string|Name|Expr $class Class name
@param array $args Constructor arguments
|
new
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function constFetch($name) : Expr\ConstFetch
{
return new Expr\ConstFetch(BuilderHelpers::normalizeName($name));
}
|
Creates a constant fetch node.
@param string|Name $name Constant name
|
constFetch
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function propertyFetch(Expr $var, $name) : Expr\PropertyFetch
{
return new Expr\PropertyFetch($var, BuilderHelpers::normalizeIdentifierOrExpr($name));
}
|
Creates a property fetch node.
@param Expr $var Variable holding object
@param string|Identifier|Expr $name Property name
|
propertyFetch
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function classConstFetch($class, $name) : Expr\ClassConstFetch
{
return new Expr\ClassConstFetch(BuilderHelpers::normalizeNameOrExpr($class), BuilderHelpers::normalizeIdentifierOrExpr($name));
}
|
Creates a class constant fetch node.
@param string|Name|Expr $class Class name
@param string|Identifier|Expr $name Constant name
|
classConstFetch
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public function concat(...$exprs) : Concat
{
$numExprs = \count($exprs);
if ($numExprs < 2) {
throw new \LogicException('Expected at least two expressions');
}
$lastConcat = $this->normalizeStringExpr($exprs[0]);
for ($i = 1; $i < $numExprs; $i++) {
$lastConcat = new Concat($lastConcat, $this->normalizeStringExpr($exprs[$i]));
}
return $lastConcat;
}
|
Creates nested Concat nodes from a list of expressions.
@param Expr|string ...$exprs Expressions or literal strings
|
concat
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderFactory.php
|
MIT
|
public static function normalizeNode($node) : Node
{
if ($node instanceof Builder) {
return $node->getNode();
}
if ($node instanceof Node) {
return $node;
}
throw new \LogicException('Expected node or builder object');
}
|
Normalizes a node: Converts builder objects to nodes.
@param Node|Builder $node The node to normalize
@return Node The normalized node
|
normalizeNode
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeStmt($node) : Stmt
{
$node = self::normalizeNode($node);
if ($node instanceof Stmt) {
return $node;
}
if ($node instanceof Expr) {
return new Stmt\Expression($node);
}
throw new \LogicException('Expected statement or expression node');
}
|
Normalizes a node to a statement.
Expressions are wrapped in a Stmt\Expression node.
@param Node|Builder $node The node to normalize
@return Stmt The normalized statement node
|
normalizeStmt
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeIdentifier($name) : Identifier
{
if ($name instanceof Identifier) {
return $name;
}
if (\is_string($name)) {
return new Identifier($name);
}
throw new \LogicException('Expected string or instance of Node\\Identifier');
}
|
Normalizes strings to Identifier.
@param string|Identifier $name The identifier to normalize
@return Identifier The normalized identifier
|
normalizeIdentifier
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeIdentifierOrExpr($name)
{
if ($name instanceof Identifier || $name instanceof Expr) {
return $name;
}
if (\is_string($name)) {
return new Identifier($name);
}
throw new \LogicException('Expected string or instance of Node\\Identifier or Node\\Expr');
}
|
Normalizes strings to Identifier, also allowing expressions.
@param string|Identifier|Expr $name The identifier to normalize
@return Identifier|Expr The normalized identifier or expression
|
normalizeIdentifierOrExpr
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeName($name) : Name
{
if ($name instanceof Name) {
return $name;
}
if (\is_string($name)) {
if (!$name) {
throw new \LogicException('Name cannot be empty');
}
if ($name[0] === '\\') {
return new Name\FullyQualified(\substr($name, 1));
}
if (0 === \strpos($name, 'namespace\\')) {
return new Name\Relative(\substr($name, \strlen('namespace\\')));
}
return new Name($name);
}
throw new \LogicException('Name must be a string or an instance of Node\\Name');
}
|
Normalizes a name: Converts string names to Name nodes.
@param Name|string $name The name to normalize
@return Name The normalized name
|
normalizeName
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeNameOrExpr($name)
{
if ($name instanceof Expr) {
return $name;
}
if (!\is_string($name) && !$name instanceof Name) {
throw new \LogicException('Name must be a string or an instance of Node\\Name or Node\\Expr');
}
return self::normalizeName($name);
}
|
Normalizes a name: Converts string names to Name nodes, while also allowing expressions.
@param Expr|Name|string $name The name to normalize
@return Name|Expr The normalized name or expression
|
normalizeNameOrExpr
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeType($type)
{
if (!\is_string($type)) {
if (!$type instanceof Name && !$type instanceof Identifier && !$type instanceof ComplexType) {
throw new \LogicException('Type must be a string, or an instance of Name, Identifier or ComplexType');
}
return $type;
}
$nullable = \false;
if (\strlen($type) > 0 && $type[0] === '?') {
$nullable = \true;
$type = \substr($type, 1);
}
$builtinTypes = ['array', 'callable', 'bool', 'int', 'float', 'string', 'iterable', 'void', 'object', 'null', 'false', 'mixed', 'never', 'true'];
$lowerType = \strtolower($type);
if (\in_array($lowerType, $builtinTypes)) {
$type = new Identifier($lowerType);
} else {
$type = self::normalizeName($type);
}
$notNullableTypes = ['void', 'mixed', 'never'];
if ($nullable && \in_array((string) $type, $notNullableTypes)) {
throw new \LogicException(\sprintf('%s type cannot be nullable', $type));
}
return $nullable ? new NullableType($type) : $type;
}
|
Normalizes a type: Converts plain-text type names into proper AST representation.
In particular, builtin types become Identifiers, custom types become Names and nullables
are wrapped in NullableType nodes.
@param string|Name|Identifier|ComplexType $type The type to normalize
@return Name|Identifier|ComplexType The normalized type
|
normalizeType
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeValue($value) : Expr
{
if ($value instanceof Node\Expr) {
return $value;
}
if (\is_null($value)) {
return new Expr\ConstFetch(new Name('null'));
}
if (\is_bool($value)) {
return new Expr\ConstFetch(new Name($value ? 'true' : 'false'));
}
if (\is_int($value)) {
return new Scalar\Int_($value);
}
if (\is_float($value)) {
return new Scalar\Float_($value);
}
if (\is_string($value)) {
return new Scalar\String_($value);
}
if (\is_array($value)) {
$items = [];
$lastKey = -1;
foreach ($value as $itemKey => $itemValue) {
// for consecutive, numeric keys don't generate keys
if (null !== $lastKey && ++$lastKey === $itemKey) {
$items[] = new Node\ArrayItem(self::normalizeValue($itemValue));
} else {
$lastKey = null;
$items[] = new Node\ArrayItem(self::normalizeValue($itemValue), self::normalizeValue($itemKey));
}
}
return new Expr\Array_($items);
}
if ($value instanceof \UnitEnum) {
return new Expr\ClassConstFetch(new FullyQualified(\get_class($value)), new Identifier($value->name));
}
throw new \LogicException('Invalid value');
}
|
Normalizes a value: Converts nulls, booleans, integers,
floats, strings and arrays into their respective nodes
@param Node\Expr|bool|null|int|float|string|array|\UnitEnum $value The value to normalize
@return Expr The normalized value
|
normalizeValue
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeDocComment($docComment) : Comment\Doc
{
if ($docComment instanceof Comment\Doc) {
return $docComment;
}
if (\is_string($docComment)) {
return new Comment\Doc($docComment);
}
throw new \LogicException('Doc comment must be a string or an instance of PhpParser\\Comment\\Doc');
}
|
Normalizes a doc comment: Converts plain strings to PhpParser\Comment\Doc.
@param Comment\Doc|string $docComment The doc comment to normalize
@return Comment\Doc The normalized doc comment
|
normalizeDocComment
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function normalizeAttribute($attribute) : Node\AttributeGroup
{
if ($attribute instanceof Node\AttributeGroup) {
return $attribute;
}
if (!$attribute instanceof Node\Attribute) {
throw new \LogicException('Attribute must be an instance of PhpParser\\Node\\Attribute or PhpParser\\Node\\AttributeGroup');
}
return new Node\AttributeGroup([$attribute]);
}
|
Normalizes a attribute: Converts attribute to the Attribute Group if needed.
@param Node\Attribute|Node\AttributeGroup $attribute
@return Node\AttributeGroup The Attribute Group
|
normalizeAttribute
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function addModifier(int $modifiers, int $modifier) : int
{
Modifiers::verifyModifier($modifiers, $modifier);
return $modifiers | $modifier;
}
|
Adds a modifier and returns new modifier bitmask.
@param int $modifiers Existing modifiers
@param int $modifier Modifier to set
@return int New modifiers
|
addModifier
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public static function addClassModifier(int $existingModifiers, int $modifierToSet) : int
{
Modifiers::verifyClassModifier($existingModifiers, $modifierToSet);
return $existingModifiers | $modifierToSet;
}
|
Adds a modifier and returns new modifier bitmask.
@return int New modifiers
|
addClassModifier
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php
|
MIT
|
public function getStartLine() : int
{
return $this->startLine;
}
|
Gets the line number the comment started on.
@return int Line number (or -1 if not available)
@phpstan-return -1|positive-int
|
getStartLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getStartFilePos() : int
{
return $this->startFilePos;
}
|
Gets the file offset the comment started on.
@return int File offset (or -1 if not available)
|
getStartFilePos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getStartTokenPos() : int
{
return $this->startTokenPos;
}
|
Gets the token offset the comment started on.
@return int Token offset (or -1 if not available)
|
getStartTokenPos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getEndLine() : int
{
return $this->endLine;
}
|
Gets the line number the comment ends on.
@return int Line number (or -1 if not available)
@phpstan-return -1|positive-int
|
getEndLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getEndFilePos() : int
{
return $this->endFilePos;
}
|
Gets the file offset the comment ends on.
@return int File offset (or -1 if not available)
|
getEndFilePos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getEndTokenPos() : int
{
return $this->endTokenPos;
}
|
Gets the token offset the comment ends on.
@return int Token offset (or -1 if not available)
|
getEndTokenPos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function getReformattedText() : string
{
$text = \str_replace("\r\n", "\n", $this->text);
$newlinePos = \strpos($text, "\n");
if (\false === $newlinePos) {
// Single line comments don't need further processing
return $text;
}
if (\preg_match('(^.*(?:\\n\\s+\\*.*)+$)', $text)) {
// Multi line comment of the type
//
// /*
// * Some text.
// * Some more text.
// */
//
// is handled by replacing the whitespace sequences before the * by a single space
return \preg_replace('(^\\s+\\*)m', ' *', $text);
}
if (\preg_match('(^/\\*\\*?\\s*\\n)', $text) && \preg_match('(\\n(\\s*)\\*/$)', $text, $matches)) {
// Multi line comment of the type
//
// /*
// Some text.
// Some more text.
// */
//
// is handled by removing the whitespace sequence on the line before the closing
// */ on all lines. So if the last line is " */", then " " is removed at the
// start of all lines.
return \preg_replace('(^' . \preg_quote($matches[1]) . ')m', '', $text);
}
if (\preg_match('(^/\\*\\*?\\s*(?!\\s))', $text, $matches)) {
// Multi line comment of the type
//
// /* Some text.
// Some more text.
// Indented text.
// Even more text. */
//
// is handled by removing the difference between the shortest whitespace prefix on all
// lines and the length of the "/* " opening sequence.
$prefixLen = $this->getShortestWhitespacePrefixLen(\substr($text, $newlinePos + 1));
$removeLen = $prefixLen - \strlen($matches[0]);
return \preg_replace('(^\\s{' . $removeLen . '})m', '', $text);
}
// No idea how to format this comment, so simply return as is
return $text;
}
|
Gets the reformatted comment text.
"Reformatted" here means that we try to clean up the whitespace at the
starts of the lines. This is necessary because we receive the comments
without leading whitespace on the first line, but with leading whitespace
on all subsequent lines.
Additionally, this normalizes CRLF newlines to LF newlines.
|
getReformattedText
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
private function getShortestWhitespacePrefixLen(string $str) : int
{
$lines = \explode("\n", $str);
$shortestPrefixLen = \PHP_INT_MAX;
foreach ($lines as $line) {
\preg_match('(^\\s*)', $line, $matches);
$prefixLen = \strlen($matches[0]);
if ($prefixLen < $shortestPrefixLen) {
$shortestPrefixLen = $prefixLen;
}
}
return $shortestPrefixLen;
}
|
Get length of shortest whitespace prefix (at the start of a line).
If there is a line with no prefix whitespace, 0 is a valid return value.
@param string $str String to check
@return int Length in characters. Tabs count as single characters.
|
getShortestWhitespacePrefixLen
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function jsonSerialize() : array
{
// Technically not a node, but we make it look like one anyway
$type = $this instanceof Comment\Doc ? 'Comment_Doc' : 'Comment';
return [
'nodeType' => $type,
'text' => $this->text,
// TODO: Rename these to include "start".
'line' => $this->startLine,
'filePos' => $this->startFilePos,
'tokenPos' => $this->startTokenPos,
'endLine' => $this->endLine,
'endFilePos' => $this->endFilePos,
'endTokenPos' => $this->endTokenPos,
];
}
|
@return array{nodeType:string, text:mixed, line:mixed, filePos:mixed}
|
jsonSerialize
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Comment.php
|
MIT
|
public function __construct(?callable $fallbackEvaluator = null)
{
$this->fallbackEvaluator = $fallbackEvaluator ?? function (Expr $expr) {
throw new ConstExprEvaluationException("Expression of type {$expr->getType()} cannot be evaluated");
};
}
|
Create a constant expression evaluator.
The provided fallback evaluator is invoked whenever a subexpression cannot be evaluated. See
class doc comment for more information.
@param callable|null $fallbackEvaluator To call if subexpression cannot be evaluated
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ConstExprEvaluator.php
|
MIT
|
public function __construct(string $message, array $attributes = [])
{
$this->rawMessage = $message;
$this->attributes = $attributes;
$this->updateMessage();
}
|
Creates an Exception signifying a parse error.
@param string $message Error message
@param array<string, mixed> $attributes Attributes of node/token where error occurred
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getRawMessage() : string
{
return $this->rawMessage;
}
|
Gets the error message
@return string Error message
|
getRawMessage
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getStartLine() : int
{
return $this->attributes['startLine'] ?? -1;
}
|
Gets the line the error starts in.
@return int Error start line
@phpstan-return -1|positive-int
|
getStartLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getEndLine() : int
{
return $this->attributes['endLine'] ?? -1;
}
|
Gets the line the error ends in.
@return int Error end line
@phpstan-return -1|positive-int
|
getEndLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getAttributes() : array
{
return $this->attributes;
}
|
Gets the attributes of the node/token the error occurred at.
@return array<string, mixed>
|
getAttributes
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function setAttributes(array $attributes) : void
{
$this->attributes = $attributes;
$this->updateMessage();
}
|
Sets the attributes of the node/token the error occurred at.
@param array<string, mixed> $attributes
|
setAttributes
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function setRawMessage(string $message) : void
{
$this->rawMessage = $message;
$this->updateMessage();
}
|
Sets the line of the PHP file the error occurred in.
@param string $message Error message
|
setRawMessage
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function setStartLine(int $line) : void
{
$this->attributes['startLine'] = $line;
$this->updateMessage();
}
|
Sets the line the error starts in.
@param int $line Error start line
|
setStartLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function hasColumnInfo() : bool
{
return isset($this->attributes['startFilePos'], $this->attributes['endFilePos']);
}
|
Returns whether the error has start and end column information.
For column information enable the startFilePos and endFilePos in the lexer options.
|
hasColumnInfo
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getStartColumn(string $code) : int
{
if (!$this->hasColumnInfo()) {
throw new \RuntimeException('Error does not have column information');
}
return $this->toColumn($code, $this->attributes['startFilePos']);
}
|
Gets the start column (1-based) into the line where the error started.
@param string $code Source code of the file
|
getStartColumn
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getEndColumn(string $code) : int
{
if (!$this->hasColumnInfo()) {
throw new \RuntimeException('Error does not have column information');
}
return $this->toColumn($code, $this->attributes['endFilePos']);
}
|
Gets the end column (1-based) into the line where the error ended.
@param string $code Source code of the file
|
getEndColumn
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function getMessageWithColumnInfo(string $code) : string
{
return \sprintf('%s from %d:%d to %d:%d', $this->getRawMessage(), $this->getStartLine(), $this->getStartColumn($code), $this->getEndLine(), $this->getEndColumn($code));
}
|
Formats message including line and column information.
@param string $code Source code associated with the error, for calculation of the columns
@return string Formatted message
|
getMessageWithColumnInfo
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
private function toColumn(string $code, int $pos) : int
{
if ($pos > \strlen($code)) {
throw new \RuntimeException('Invalid position information');
}
$lineStartPos = \strrpos($code, "\n", $pos - \strlen($code));
if (\false === $lineStartPos) {
$lineStartPos = -1;
}
return $pos - $lineStartPos;
}
|
Converts a file offset into a column.
@param string $code Source code that $pos indexes into
@param int $pos 0-based position in $code
@return int 1-based column (relative to start of line)
|
toColumn
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
protected function updateMessage() : void
{
$this->message = $this->rawMessage;
if (-1 === $this->getStartLine()) {
$this->message .= ' on unknown line';
} else {
$this->message .= ' on line ' . $this->getStartLine();
}
}
|
Updates the exception message after a change to rawMessage or rawLine.
|
updateMessage
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Error.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Error.php
|
MIT
|
public function tokenize(string $code, ?ErrorHandler $errorHandler = null) : array
{
if (null === $errorHandler) {
$errorHandler = new ErrorHandler\Throwing();
}
$scream = \ini_set('xdebug.scream', '0');
$tokens = @Token::tokenize($code);
$this->postprocessTokens($tokens, $errorHandler);
if (\false !== $scream) {
\ini_set('xdebug.scream', $scream);
}
return $tokens;
}
|
Tokenize the provided source code.
The token array is in the same format as provided by the PhpToken::tokenize() method in
PHP 8.0. The tokens are instances of PhpParser\Token, to abstract over a polyfill
implementation in earlier PHP version.
The token array is terminated by a sentinel token with token ID 0.
The token array does not discard any tokens (i.e. whitespace and comments are included).
The token position attributes are against this token array.
@param string $code The source code to tokenize.
@param ErrorHandler|null $errorHandler Error handler to use for lexing errors. Defaults to
ErrorHandler\Throwing.
@return Token[] Tokens
|
tokenize
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/Lexer.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/Lexer.php
|
MIT
|
public function __construct(ErrorHandler $errorHandler)
{
$this->errorHandler = $errorHandler;
}
|
Create a name context.
@param ErrorHandler $errorHandler Error handling used to report errors
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function startNamespace(?Name $namespace = null) : void
{
$this->namespace = $namespace;
$this->origAliases = $this->aliases = [Stmt\Use_::TYPE_NORMAL => [], Stmt\Use_::TYPE_FUNCTION => [], Stmt\Use_::TYPE_CONSTANT => []];
}
|
Start a new namespace.
This also resets the alias table.
@param Name|null $namespace Null is the global namespace
|
startNamespace
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) : void
{
// Constant names are case sensitive, everything else case insensitive
if ($type === Stmt\Use_::TYPE_CONSTANT) {
$aliasLookupName = $aliasName;
} else {
$aliasLookupName = \strtolower($aliasName);
}
if (isset($this->aliases[$type][$aliasLookupName])) {
$typeStringMap = [Stmt\Use_::TYPE_NORMAL => '', Stmt\Use_::TYPE_FUNCTION => 'function ', Stmt\Use_::TYPE_CONSTANT => 'const '];
$this->errorHandler->handleError(new Error(\sprintf('Cannot use %s%s as %s because the name is already in use', $typeStringMap[$type], $name, $aliasName), $errorAttrs));
return;
}
$this->aliases[$type][$aliasLookupName] = $name;
$this->origAliases[$type][$aliasName] = $name;
}
|
Add an alias / import.
@param Name $name Original name
@param string $aliasName Aliased name
@param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_*
@param array<string, mixed> $errorAttrs Attributes to use to report an error
|
addAlias
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function getNamespace() : ?Name
{
return $this->namespace;
}
|
Get current namespace.
@return null|Name Namespace (or null if global namespace)
|
getNamespace
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function getResolvedName(Name $name, int $type) : ?Name
{
// don't resolve special class names
if ($type === Stmt\Use_::TYPE_NORMAL && $name->isSpecialClassName()) {
if (!$name->isUnqualified()) {
$this->errorHandler->handleError(new Error(\sprintf("'\\%s' is an invalid class name", $name->toString()), $name->getAttributes()));
}
return $name;
}
// fully qualified names are already resolved
if ($name->isFullyQualified()) {
return $name;
}
// Try to resolve aliases
if (null !== ($resolvedName = $this->resolveAlias($name, $type))) {
return $resolvedName;
}
if ($type !== Stmt\Use_::TYPE_NORMAL && $name->isUnqualified()) {
if (null === $this->namespace) {
// outside of a namespace unaliased unqualified is same as fully qualified
return new FullyQualified($name, $name->getAttributes());
}
// Cannot resolve statically
return null;
}
// if no alias exists prepend current namespace
return FullyQualified::concat($this->namespace, $name, $name->getAttributes());
}
|
Get resolved name.
@param Name $name Name to resolve
@param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_{FUNCTION|CONSTANT}
@return null|Name Resolved name, or null if static resolution is not possible
|
getResolvedName
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function getResolvedClassName(Name $name) : Name
{
return $this->getResolvedName($name, Stmt\Use_::TYPE_NORMAL);
}
|
Get resolved class name.
@param Name $name Class ame to resolve
@return Name Resolved name
|
getResolvedClassName
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function getPossibleNames(string $name, int $type) : array
{
$lcName = \strtolower($name);
if ($type === Stmt\Use_::TYPE_NORMAL) {
// self, parent and static must always be unqualified
if ($lcName === "self" || $lcName === "parent" || $lcName === "static") {
return [new Name($name)];
}
}
// Collect possible ways to write this name, starting with the fully-qualified name
$possibleNames = [new FullyQualified($name)];
if (null !== ($nsRelativeName = $this->getNamespaceRelativeName($name, $lcName, $type))) {
// Make sure there is no alias that makes the normally namespace-relative name
// into something else
if (null === $this->resolveAlias($nsRelativeName, $type)) {
$possibleNames[] = $nsRelativeName;
}
}
// Check for relevant namespace use statements
foreach ($this->origAliases[Stmt\Use_::TYPE_NORMAL] as $alias => $orig) {
$lcOrig = $orig->toLowerString();
if (0 === \strpos($lcName, $lcOrig . '\\')) {
$possibleNames[] = new Name($alias . \substr($name, \strlen($lcOrig)));
}
}
// Check for relevant type-specific use statements
foreach ($this->origAliases[$type] as $alias => $orig) {
if ($type === Stmt\Use_::TYPE_CONSTANT) {
// Constants are complicated-sensitive
$normalizedOrig = $this->normalizeConstName($orig->toString());
if ($normalizedOrig === $this->normalizeConstName($name)) {
$possibleNames[] = new Name($alias);
}
} else {
// Everything else is case-insensitive
if ($orig->toLowerString() === $lcName) {
$possibleNames[] = new Name($alias);
}
}
}
return $possibleNames;
}
|
Get possible ways of writing a fully qualified name (e.g., by making use of aliases).
@param string $name Fully-qualified name (without leading namespace separator)
@param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_*
@return Name[] Possible representations of the name
|
getPossibleNames
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function getShortName(string $name, int $type) : Name
{
$possibleNames = $this->getPossibleNames($name, $type);
// Find shortest name
$shortestName = null;
$shortestLength = \INF;
foreach ($possibleNames as $possibleName) {
$length = \strlen($possibleName->toCodeString());
if ($length < $shortestLength) {
$shortestName = $possibleName;
$shortestLength = $length;
}
}
return $shortestName;
}
|
Get shortest representation of this fully-qualified name.
@param string $name Fully-qualified name (without leading namespace separator)
@param Stmt\Use_::TYPE_* $type One of Stmt\Use_::TYPE_*
@return Name Shortest representation
|
getShortName
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NameContext.php
|
MIT
|
public function __construct(array $attributes = [])
{
$this->attributes = $attributes;
}
|
Creates a Node.
@param array<string, mixed> $attributes Array of attributes
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getLine() : int
{
return $this->attributes['startLine'] ?? -1;
}
|
Gets line the node started in (alias of getStartLine).
@return int Start line (or -1 if not available)
@phpstan-return -1|positive-int
|
getLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getStartLine() : int
{
return $this->attributes['startLine'] ?? -1;
}
|
Gets line the node started in.
Requires the 'startLine' attribute to be enabled in the lexer (enabled by default).
@return int Start line (or -1 if not available)
@phpstan-return -1|positive-int
|
getStartLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getEndLine() : int
{
return $this->attributes['endLine'] ?? -1;
}
|
Gets the line the node ended in.
Requires the 'endLine' attribute to be enabled in the lexer (enabled by default).
@return int End line (or -1 if not available)
@phpstan-return -1|positive-int
|
getEndLine
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getStartTokenPos() : int
{
return $this->attributes['startTokenPos'] ?? -1;
}
|
Gets the token offset of the first token that is part of this node.
The offset is an index into the array returned by Lexer::getTokens().
Requires the 'startTokenPos' attribute to be enabled in the lexer (DISABLED by default).
@return int Token start position (or -1 if not available)
|
getStartTokenPos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getEndTokenPos() : int
{
return $this->attributes['endTokenPos'] ?? -1;
}
|
Gets the token offset of the last token that is part of this node.
The offset is an index into the array returned by Lexer::getTokens().
Requires the 'endTokenPos' attribute to be enabled in the lexer (DISABLED by default).
@return int Token end position (or -1 if not available)
|
getEndTokenPos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getStartFilePos() : int
{
return $this->attributes['startFilePos'] ?? -1;
}
|
Gets the file offset of the first character that is part of this node.
Requires the 'startFilePos' attribute to be enabled in the lexer (DISABLED by default).
@return int File start position (or -1 if not available)
|
getStartFilePos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getEndFilePos() : int
{
return $this->attributes['endFilePos'] ?? -1;
}
|
Gets the file offset of the last character that is part of this node.
Requires the 'endFilePos' attribute to be enabled in the lexer (DISABLED by default).
@return int File end position (or -1 if not available)
|
getEndFilePos
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getComments() : array
{
return $this->attributes['comments'] ?? [];
}
|
Gets all comments directly preceding this node.
The comments are also available through the "comments" attribute.
@return Comment[]
|
getComments
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function getDocComment() : ?Comment\Doc
{
$comments = $this->getComments();
for ($i = \count($comments) - 1; $i >= 0; $i--) {
$comment = $comments[$i];
if ($comment instanceof Comment\Doc) {
return $comment;
}
}
return null;
}
|
Gets the doc comment of the node.
@return null|Comment\Doc Doc comment object or null
|
getDocComment
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function setDocComment(Comment\Doc $docComment) : void
{
$comments = $this->getComments();
for ($i = \count($comments) - 1; $i >= 0; $i--) {
if ($comments[$i] instanceof Comment\Doc) {
// Replace existing doc comment.
$comments[$i] = $docComment;
$this->setAttribute('comments', $comments);
return;
}
}
// Append new doc comment.
$comments[] = $docComment;
$this->setAttribute('comments', $comments);
}
|
Sets the doc comment of the node.
This will either replace an existing doc comment or add it to the comments array.
@param Comment\Doc $docComment Doc comment to set
|
setDocComment
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php
|
MIT
|
public function __construct(array $options = [])
{
$this->dumpComments = !empty($options['dumpComments']);
$this->dumpPositions = !empty($options['dumpPositions']);
$this->dumpOtherAttributes = !empty($options['dumpOtherAttributes']);
}
|
Constructs a NodeDumper.
Supported options:
* bool dumpComments: Whether comments should be dumped.
* bool dumpPositions: Whether line/offset information should be dumped. To dump offset
information, the code needs to be passed to dump().
* bool dumpOtherAttributes: Whether non-comment, non-position attributes should be dumped.
@param array $options Options (see description)
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
MIT
|
public function dump($node, ?string $code = null) : string
{
$this->code = $code;
$this->res = '';
$this->nl = "\n";
$this->dumpRecursive($node, \false);
return $this->res;
}
|
Dumps a node or array.
@param array|Node $node Node or array to dump
@param string|null $code Code corresponding to dumped AST. This only needs to be passed if
the dumpPositions option is enabled and the dumping of node offsets
is desired.
@return string Dumped value
|
dump
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
MIT
|
protected function dumpPosition(Node $node) : ?string
{
if (!$node->hasAttribute('startLine') || !$node->hasAttribute('endLine')) {
return null;
}
$start = $node->getStartLine();
$end = $node->getEndLine();
if ($node->hasAttribute('startFilePos') && $node->hasAttribute('endFilePos') && null !== $this->code) {
$start .= ':' . $this->toColumn($this->code, $node->getStartFilePos());
$end .= ':' . $this->toColumn($this->code, $node->getEndFilePos());
}
return "[{$start} - {$end}]";
}
|
Dump node position, if possible.
@param Node $node Node for which to dump position
@return string|null Dump of position, or null if position information not available
|
dumpPosition
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeDumper.php
|
MIT
|
public function find($nodes, callable $filter) : array
{
if ($nodes === []) {
return [];
}
if (!\is_array($nodes)) {
$nodes = [$nodes];
}
$visitor = new FindingVisitor($filter);
$traverser = new NodeTraverser($visitor);
$traverser->traverse($nodes);
return $visitor->getFoundNodes();
}
|
Find all nodes satisfying a filter callback.
@param Node|Node[] $nodes Single node or array of nodes to search in
@param callable $filter Filter callback: function(Node $node) : bool
@return Node[] Found nodes satisfying the filter callback
|
find
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
MIT
|
public function findInstanceOf($nodes, string $class) : array
{
return $this->find($nodes, function ($node) use($class) {
return $node instanceof $class;
});
}
|
Find all nodes that are instances of a certain class.
@template TNode as Node
@param Node|Node[] $nodes Single node or array of nodes to search in
@param class-string<TNode> $class Class name
@return TNode[] Found nodes (all instances of $class)
|
findInstanceOf
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
MIT
|
public function findFirst($nodes, callable $filter) : ?Node
{
if ($nodes === []) {
return null;
}
if (!\is_array($nodes)) {
$nodes = [$nodes];
}
$visitor = new FirstFindingVisitor($filter);
$traverser = new NodeTraverser($visitor);
$traverser->traverse($nodes);
return $visitor->getFoundNode();
}
|
Find first node satisfying a filter callback.
@param Node|Node[] $nodes Single node or array of nodes to search in
@param callable $filter Filter callback: function(Node $node) : bool
@return null|Node Found node (or null if none found)
|
findFirst
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
MIT
|
public function findFirstInstanceOf($nodes, string $class) : ?Node
{
return $this->findFirst($nodes, function ($node) use($class) {
return $node instanceof $class;
});
}
|
Find first node that is an instance of a certain class.
@template TNode as Node
@param Node|Node[] $nodes Single node or array of nodes to search in
@param class-string<TNode> $class Class name
@return null|TNode Found node, which is an instance of $class (or null if none found)
|
findFirstInstanceOf
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
|
MIT
|
public function __construct(NodeVisitor ...$visitors)
{
$this->visitors = $visitors;
}
|
Create a traverser with the given visitors.
@param NodeVisitor ...$visitors Node visitors
|
__construct
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
MIT
|
public function addVisitor(NodeVisitor $visitor) : void
{
$this->visitors[] = $visitor;
}
|
Adds a visitor.
@param NodeVisitor $visitor Visitor to add
|
addVisitor
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
MIT
|
public function traverse(array $nodes) : array
{
$this->stopTraversal = \false;
foreach ($this->visitors as $visitor) {
if (null !== ($return = $visitor->beforeTraverse($nodes))) {
$nodes = $return;
}
}
$nodes = $this->traverseArray($nodes);
for ($i = \count($this->visitors) - 1; $i >= 0; --$i) {
$visitor = $this->visitors[$i];
if (null !== ($return = $visitor->afterTraverse($nodes))) {
$nodes = $return;
}
}
return $nodes;
}
|
Traverses an array of nodes using the registered visitors.
@param Node[] $nodes Array of nodes
@return Node[] Traversed array of nodes
|
traverse
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
MIT
|
protected function traverseNode(Node $node) : void
{
foreach ($node->getSubNodeNames() as $name) {
$subNode = $node->{$name};
if (\is_array($subNode)) {
$node->{$name} = $this->traverseArray($subNode);
if ($this->stopTraversal) {
break;
}
continue;
}
if (!$subNode instanceof Node) {
continue;
}
$traverseChildren = \true;
$visitorIndex = -1;
foreach ($this->visitors as $visitorIndex => $visitor) {
$return = $visitor->enterNode($subNode);
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($subNode, $return);
$subNode = $node->{$name} = $return;
} elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) {
$traverseChildren = \false;
} elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
$traverseChildren = \false;
break;
} elseif (NodeVisitor::STOP_TRAVERSAL === $return) {
$this->stopTraversal = \true;
break 2;
} elseif (NodeVisitor::REPLACE_WITH_NULL === $return) {
$node->{$name} = null;
continue 2;
} else {
throw new \LogicException('enterNode() returned invalid value of type ' . \gettype($return));
}
}
}
if ($traverseChildren) {
$this->traverseNode($subNode);
if ($this->stopTraversal) {
break;
}
}
for (; $visitorIndex >= 0; --$visitorIndex) {
$visitor = $this->visitors[$visitorIndex];
$return = $visitor->leaveNode($subNode);
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($subNode, $return);
$subNode = $node->{$name} = $return;
} elseif (NodeVisitor::STOP_TRAVERSAL === $return) {
$this->stopTraversal = \true;
break 2;
} elseif (NodeVisitor::REPLACE_WITH_NULL === $return) {
$node->{$name} = null;
break;
} 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));
}
}
}
}
}
|
Recursively traverse a node.
@param Node $node Node to traverse.
|
traverseNode
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
MIT
|
protected function traverseArray(array $nodes) : array
{
$doNodes = [];
foreach ($nodes as $i => $node) {
if (!$node instanceof Node) {
if (\is_array($node)) {
throw new \LogicException('Invalid node structure: Contains nested arrays');
}
continue;
}
$traverseChildren = \true;
$visitorIndex = -1;
foreach ($this->visitors as $visitorIndex => $visitor) {
$return = $visitor->enterNode($node);
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($node, $return);
$nodes[$i] = $node = $return;
} elseif (\is_array($return)) {
$doNodes[] = [$i, $return];
continue 2;
} elseif (NodeVisitor::REMOVE_NODE === $return) {
$doNodes[] = [$i, []];
continue 2;
} elseif (NodeVisitor::DONT_TRAVERSE_CHILDREN === $return) {
$traverseChildren = \false;
} elseif (NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN === $return) {
$traverseChildren = \false;
break;
} elseif (NodeVisitor::STOP_TRAVERSAL === $return) {
$this->stopTraversal = \true;
break 2;
} elseif (NodeVisitor::REPLACE_WITH_NULL === $return) {
throw new \LogicException('REPLACE_WITH_NULL can not be used if the parent structure is an array');
} else {
throw new \LogicException('enterNode() returned invalid value of type ' . \gettype($return));
}
}
}
if ($traverseChildren) {
$this->traverseNode($node);
if ($this->stopTraversal) {
break;
}
}
for (; $visitorIndex >= 0; --$visitorIndex) {
$visitor = $this->visitors[$visitorIndex];
$return = $visitor->leaveNode($node);
if (null !== $return) {
if ($return instanceof Node) {
$this->ensureReplacementReasonable($node, $return);
$nodes[$i] = $node = $return;
} elseif (\is_array($return)) {
$doNodes[] = [$i, $return];
break;
} elseif (NodeVisitor::REMOVE_NODE === $return) {
$doNodes[] = [$i, []];
break;
} elseif (NodeVisitor::STOP_TRAVERSAL === $return) {
$this->stopTraversal = \true;
break 2;
} elseif (NodeVisitor::REPLACE_WITH_NULL === $return) {
throw new \LogicException('REPLACE_WITH_NULL can not be used if the parent structure is an array');
} else {
throw new \LogicException('leaveNode() returned invalid value of type ' . \gettype($return));
}
}
}
}
if (!empty($doNodes)) {
while (list($i, $replace) = \array_pop($doNodes)) {
\array_splice($nodes, $i, 1, $replace);
}
}
return $nodes;
}
|
Recursively traverse array (usually of nodes).
@param array $nodes Array to traverse
@return array Result of traversal (may be original array or changed one)
|
traverseArray
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/NodeTraverser.php
|
MIT
|
public function parse(string $code, ?ErrorHandler $errorHandler = null) : ?array
{
$this->errorHandler = $errorHandler ?: new ErrorHandler\Throwing();
$this->createdArrays = new \SplObjectStorage();
$this->tokens = $this->lexer->tokenize($code, $this->errorHandler);
$result = $this->doParse();
// Report errors for any empty elements used inside arrays. This is delayed until after the main parse,
// because we don't know a priori whether a given array expression will be used in a destructuring context
// or not.
foreach ($this->createdArrays as $node) {
foreach ($node->items as $item) {
if ($item->value instanceof Expr\Error) {
$this->errorHandler->handleError(new Error('Cannot use empty array elements in arrays', $item->getAttributes()));
}
}
}
// Clear out some of the interior state, so we don't hold onto unnecessary
// memory between uses of the parser
$this->tokenStartStack = [];
$this->tokenEndStack = [];
$this->semStack = [];
$this->semValue = null;
$this->createdArrays = null;
if ($result !== null) {
$traverser = new NodeTraverser(new CommentAnnotatingVisitor($this->tokens));
$traverser->traverse($result);
}
return $result;
}
|
Parses PHP code into a node tree.
If a non-throwing error handler is used, the parser will continue parsing after an error
occurred and attempt to build a partial AST.
@param string $code The source code to parse
@param ErrorHandler|null $errorHandler Error handler to use for lexer/parser errors, defaults
to ErrorHandler\Throwing.
@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).
|
parse
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function getErrorMessage(int $symbol, int $state) : string
{
$expectedString = '';
if ($expected = $this->getExpectedTokens($state)) {
$expectedString = ', expecting ' . \implode(' or ', $expected);
}
return 'Syntax error, unexpected ' . $this->symbolToName[$symbol] . $expectedString;
}
|
Format error message including expected tokens.
@param int $symbol Unexpected symbol
@param int $state State at time of error
@return string Formatted error message
|
getErrorMessage
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function getAttributes(int $tokenStartPos, int $tokenEndPos) : array
{
$startToken = $this->tokens[$tokenStartPos];
$afterEndToken = $this->tokens[$tokenEndPos + 1];
return ['startLine' => $startToken->line, 'startTokenPos' => $tokenStartPos, 'startFilePos' => $startToken->pos, 'endLine' => $afterEndToken->line, 'endTokenPos' => $tokenEndPos, 'endFilePos' => $afterEndToken->pos - 1];
}
|
Get attributes for a node with the given start and end token positions.
@param int $tokenStartPos Token position the node starts at
@param int $tokenEndPos Token position the node ends at
@return array<string, mixed> Attributes
|
getAttributes
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function getAttributesForToken(int $tokenPos) : array
{
if ($tokenPos < \count($this->tokens) - 1) {
return $this->getAttributes($tokenPos, $tokenPos);
}
// Get attributes for the sentinel token.
$token = $this->tokens[$tokenPos];
return ['startLine' => $token->line, 'startTokenPos' => $tokenPos, 'startFilePos' => $token->pos, 'endLine' => $token->line, 'endTokenPos' => $tokenPos, 'endFilePos' => $token->pos];
}
|
Get attributes for a single token at the given token position.
@return array<string, mixed> Attributes
|
getAttributesForToken
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function handleNamespaces(array $stmts) : array
{
$hasErrored = \false;
$style = $this->getNamespacingStyle($stmts);
if (null === $style) {
// not namespaced, nothing to do
return $stmts;
}
if ('brace' === $style) {
// 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 Node\Stmt\Namespace_) {
$afterFirstNamespace = \true;
} 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()));
$hasErrored = \true;
// Avoid one error for every statement
}
}
return $stmts;
} else {
// For semicolon namespaces we have to move the statements after a namespace declaration into ->stmts
$resultStmts = [];
$targetStmts =& $resultStmts;
$lastNs = null;
foreach ($stmts as $stmt) {
if ($stmt instanceof Node\Stmt\Namespace_) {
if ($lastNs !== null) {
$this->fixupNamespaceAttributes($lastNs);
}
if ($stmt->stmts === null) {
$stmt->stmts = [];
$targetStmts =& $stmt->stmts;
$resultStmts[] = $stmt;
} else {
// This handles the invalid case of mixed style namespaces
$resultStmts[] = $stmt;
$targetStmts =& $resultStmts;
}
$lastNs = $stmt;
} elseif ($stmt instanceof Node\Stmt\HaltCompiler) {
// __halt_compiler() is not moved into the namespace
$resultStmts[] = $stmt;
} else {
$targetStmts[] = $stmt;
}
}
if ($lastNs !== null) {
$this->fixupNamespaceAttributes($lastNs);
}
return $resultStmts;
}
}
|
Moves statements of semicolon-style namespaces into $ns->stmts and checks various error conditions.
@param Node\Stmt[] $stmts
@return Node\Stmt[]
|
handleNamespaces
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
private function getNamespacingStyle(array $stmts) : ?string
{
$style = null;
$hasNotAllowedStmts = \false;
foreach ($stmts as $i => $stmt) {
if ($stmt instanceof Node\Stmt\Namespace_) {
$currentStyle = null === $stmt->stmts ? 'semicolon' : 'brace';
if (null === $style) {
$style = $currentStyle;
if ($hasNotAllowedStmts) {
$this->emitError(new Error('Namespace declaration statement has to be the very first statement in the script', $this->getNamespaceErrorAttributes($stmt)));
}
} elseif ($style !== $currentStyle) {
$this->emitError(new Error('Cannot mix bracketed namespace declarations with unbracketed namespace declarations', $this->getNamespaceErrorAttributes($stmt)));
// Treat like semicolon style for namespace normalization
return 'semicolon';
}
continue;
}
/* declare(), __halt_compiler() and nops can be used before a namespace declaration */
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 Node\Stmt\InlineHTML && \preg_match('/\\A#!.*\\r?\\n\\z/', $stmt->value)) {
continue;
}
/* Everything else if forbidden before namespace declarations */
$hasNotAllowedStmts = \true;
}
return $style;
}
|
Determine namespacing style (semicolon or brace)
@param Node[] $stmts Top-level statements.
@return null|string One of "semicolon", "brace" or null (no namespaces)
|
getNamespacingStyle
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function getAttributesAt(int $stackPos) : array
{
return $this->getAttributes($this->tokenStartStack[$stackPos], $this->tokenEndStack[$stackPos]);
}
|
Get combined start and end attributes at a stack location
@param int $stackPos Stack location
@return array<string, mixed> Combined start and end attributes
|
getAttributesAt
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function parseNumString(string $str, array $attributes)
{
if (!\preg_match('/^(?:0|-?[1-9][0-9]*)$/', $str)) {
return new String_($str, $attributes);
}
$num = +$str;
if (!\is_int($num)) {
return new String_($str, $attributes);
}
return new Int_($num, $attributes);
}
|
Parse a T_NUM_STRING token into either an integer or string node.
@param string $str Number string
@param array<string, mixed> $attributes Attributes
@return Int_|String_ Integer or string node.
|
parseNumString
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function parseDocString(string $startToken, $contents, string $endToken, array $attributes, array $endTokenAttributes, bool $parseUnicodeEscape) : Expr
{
$kind = \strpos($startToken, "'") === \false ? String_::KIND_HEREDOC : String_::KIND_NOWDOC;
$regex = '/\\A[bB]?<<<[ \\t]*[\'"]?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*)[\'"]?(?:\\r\\n|\\n|\\r)\\z/';
$result = \preg_match($regex, $startToken, $matches);
\assert($result === 1);
$label = $matches[1];
$result = \preg_match('/\\A[ \\t]*/', $endToken, $matches);
\assert($result === 1);
$indentation = $matches[0];
$attributes['kind'] = $kind;
$attributes['docLabel'] = $label;
$attributes['docIndentation'] = $indentation;
$indentHasSpaces = \false !== \strpos($indentation, " ");
$indentHasTabs = \false !== \strpos($indentation, "\t");
if ($indentHasSpaces && $indentHasTabs) {
$this->emitError(new Error('Invalid indentation - tabs and spaces cannot be mixed', $endTokenAttributes));
// Proceed processing as if this doc string is not indented
$indentation = '';
}
$indentLen = \strlen($indentation);
$indentChar = $indentHasSpaces ? " " : "\t";
if (\is_string($contents)) {
if ($contents === '') {
$attributes['rawValue'] = $contents;
return new String_('', $attributes);
}
$contents = $this->stripIndentation($contents, $indentLen, $indentChar, \true, \true, $attributes);
$contents = \preg_replace('~(\\r\\n|\\n|\\r)\\z~', '', $contents);
$attributes['rawValue'] = $contents;
if ($kind === String_::KIND_HEREDOC) {
$contents = String_::parseEscapeSequences($contents, null, $parseUnicodeEscape);
}
return new String_($contents, $attributes);
} else {
\assert(\count($contents) > 0);
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());
}
$newContents = [];
foreach ($contents as $i => $part) {
if ($part instanceof Node\InterpolatedStringPart) {
$isLast = $i === \count($contents) - 1;
$part->value = $this->stripIndentation($part->value, $indentLen, $indentChar, $i === 0, $isLast, $part->getAttributes());
if ($isLast) {
$part->value = \preg_replace('~(\\r\\n|\\n|\\r)\\z~', '', $part->value);
}
$part->setAttribute('rawValue', $part->value);
$part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape);
if ('' === $part->value) {
continue;
}
}
$newContents[] = $part;
}
return new InterpolatedString($newContents, $attributes);
}
}
|
@param string|(Expr|InterpolatedStringPart)[] $contents
@param array<string, mixed> $attributes
@param array<string, mixed> $endTokenAttributes
|
parseDocString
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function getCommentBeforeToken(int $tokenPos) : ?Comment
{
while (--$tokenPos >= 0) {
$token = $this->tokens[$tokenPos];
if (!isset($this->dropTokens[$token->id])) {
break;
}
if ($token->id === \T_COMMENT || $token->id === \T_DOC_COMMENT) {
return $this->createCommentFromToken($token, $tokenPos);
}
}
return null;
}
|
Get last comment before the given token position, if any
|
getCommentBeforeToken
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function maybeCreateZeroLengthNop(int $tokenPos) : ?Nop
{
$comment = $this->getCommentBeforeToken($tokenPos);
if ($comment === null) {
return null;
}
$commentEndLine = $comment->getEndLine();
$commentEndFilePos = $comment->getEndFilePos();
$commentEndTokenPos = $comment->getEndTokenPos();
$attributes = ['startLine' => $commentEndLine, 'endLine' => $commentEndLine, 'startFilePos' => $commentEndFilePos + 1, 'endFilePos' => $commentEndFilePos, 'startTokenPos' => $commentEndTokenPos + 1, 'endTokenPos' => $commentEndTokenPos];
return new Nop($attributes);
}
|
Create a zero-length nop to capture preceding comments, if any.
|
maybeCreateZeroLengthNop
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
private function isSimpleExit(array $args) : bool
{
if (\count($args) === 0) {
return \true;
}
if (\count($args) === 1) {
$arg = $args[0];
return $arg instanceof Arg && $arg->name === null && $arg->byRef === \false && $arg->unpack === \false;
}
return \false;
}
|
@param array<Node\Arg|Node\VariadicPlaceholder> $args
|
isSimpleExit
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function createExitExpr(string $name, int $namePos, array $args, array $attrs) : Expr
{
if ($this->isSimpleExit($args)) {
// Create Exit node for backwards compatibility.
$attrs['kind'] = \strtolower($name) === 'exit' ? Expr\Exit_::KIND_EXIT : Expr\Exit_::KIND_DIE;
return new Expr\Exit_(\count($args) === 1 ? $args[0]->value : null, $attrs);
}
return new Expr\FuncCall(new Name($name, $this->getAttributesAt($namePos)), $args, $attrs);
}
|
@param array<Node\Arg|Node\VariadicPlaceholder> $args
@param array<string, mixed> $attrs
|
createExitExpr
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
protected function createTokenMap() : array
{
$tokenMap = [];
// Single-char tokens use an identity mapping.
for ($i = 0; $i < 256; ++$i) {
$tokenMap[$i] = $i;
}
foreach ($this->symbolToName as $name) {
if ($name[0] === 'T') {
$tokenMap[\constant($name)] = \constant(static::class . '::' . $name);
}
}
// T_OPEN_TAG_WITH_ECHO with dropped T_OPEN_TAG results in T_ECHO
$tokenMap[\T_OPEN_TAG_WITH_ECHO] = static::T_ECHO;
// T_CLOSE_TAG is equivalent to ';'
$tokenMap[\T_CLOSE_TAG] = \ord(';');
// We have created a map from PHP token IDs to external symbol IDs.
// Now map them to the internal symbol ID.
$fullTokenMap = [];
foreach ($tokenMap as $phpToken => $extSymbol) {
$intSymbol = $this->tokenToSymbol[$extSymbol];
if ($intSymbol === $this->invalidSymbol) {
continue;
}
$fullTokenMap[$phpToken] = $intSymbol;
}
return $fullTokenMap;
}
|
Creates the token map.
The token map maps the PHP internal token identifiers
to the identifiers used by the Parser. Additionally it
maps T_OPEN_TAG_WITH_ECHO to T_ECHO and T_CLOSE_TAG to ';'.
@return array<int, int> The token map
|
createTokenMap
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserAbstract.php
|
MIT
|
public function createForVersion(PhpVersion $version) : Parser
{
if ($version->isHostVersion()) {
$lexer = new Lexer();
} else {
$lexer = new Lexer\Emulative($version);
}
if ($version->id >= 80000) {
return new Php8($lexer, $version);
}
return new Php7($lexer, $version);
}
|
Create a parser targeting the given version on a best-effort basis. The parser will generally
accept code for the newest supported version, but will try to accommodate code that becomes
invalid in newer versions or changes in interpretation.
|
createForVersion
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
MIT
|
public function createForNewestSupportedVersion() : Parser
{
return $this->createForVersion(PhpVersion::getNewestSupported());
}
|
Create a parser targeting the newest version supported by this library. Code for older
versions will be accepted if there have been no relevant backwards-compatibility breaks in
PHP.
|
createForNewestSupportedVersion
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
MIT
|
public function createForHostVersion() : Parser
{
return $this->createForVersion(PhpVersion::getHostVersion());
}
|
Create a parser targeting the host PHP version, that is the PHP version we're currently
running on. This parser will not use any token emulation.
|
createForHostVersion
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/ParserFactory.php
|
MIT
|
public static function fromComponents(int $major, int $minor) : self
{
return new self($major * 10000 + $minor * 100);
}
|
Create a PhpVersion object from major and minor version components.
|
fromComponents
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
public static function getNewestSupported() : self
{
return self::fromComponents(8, 4);
}
|
Get the newest PHP version supported by this library. Support for this version may be partial,
if it is still under development.
|
getNewestSupported
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
public static function getHostVersion() : self
{
return self::fromComponents(\PHP_MAJOR_VERSION, \PHP_MINOR_VERSION);
}
|
Get the host PHP version, that is the PHP version we're currently running on.
|
getHostVersion
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
public static function fromString(string $version) : self
{
if (!\preg_match('/^(\\d+)\\.(\\d+)/', $version, $matches)) {
throw new \LogicException("Invalid PHP version \"{$version}\"");
}
return self::fromComponents((int) $matches[1], (int) $matches[2]);
}
|
Parse the version from a string like "8.1".
|
fromString
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
public function equals(PhpVersion $other) : bool
{
return $this->id === $other->id;
}
|
Check whether two versions are the same.
|
equals
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
public function newerOrEqual(PhpVersion $other) : bool
{
return $this->id >= $other->id;
}
|
Check whether this version is greater than or equal to the argument.
|
newerOrEqual
|
php
|
deptrac/deptrac
|
vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
https://github.com/deptrac/deptrac/blob/master/vendor/nikic/php-parser/lib/PhpParser/PhpVersion.php
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.