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
private function resolveSingleType(string $type, Context $context) : object { switch (\true) { case $this->isKeyword($type): return $this->resolveKeyword($type); case $this->isFqsen($type): return $this->resolveTypedObject($type); case $this->isPartialStructuralElementName($type): return $this->resolveTypedObject($type, $context); // @codeCoverageIgnoreStart default: // I haven't got the foggiest how the logic would come here but added this as a defense. throw new RuntimeException('Unable to resolve type "' . $type . '", there is no known method to resolve it'); } // @codeCoverageIgnoreEnd }
resolve the given type into a type object @param string $type the type string, representing a single type @return Type|Array_|Object_ @psalm-mutation-free
resolveSingleType
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
public function addKeyword(string $keyword, string $typeClassName) : void { if (!class_exists($typeClassName)) { throw new InvalidArgumentException('The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class' . ' but we could not find the class ' . $typeClassName); } $interfaces = class_implements($typeClassName); if ($interfaces === \false) { throw new InvalidArgumentException('The Value Object that needs to be created with a keyword "' . $keyword . '" must be an existing class' . ' but we could not find the class ' . $typeClassName); } if (!in_array(Type::class, $interfaces, \true)) { throw new InvalidArgumentException('The class "' . $typeClassName . '" must implement the interface "phpDocumentor\\Reflection\\Type"'); } $this->keywords[$keyword] = $typeClassName; }
Adds a keyword to the list of Keywords and associates it with a specific Value Object. @psalm-param class-string<Type> $typeClassName
addKeyword
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function isKeyword(string $type) : bool { return array_key_exists(strtolower($type), $this->keywords); }
Detects whether the given type represents a PHPDoc keyword. @param string $type A relative or absolute type as defined in the phpDocumentor documentation. @psalm-mutation-free
isKeyword
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function isPartialStructuralElementName(string $type) : bool { return isset($type[0]) && $type[0] !== self::OPERATOR_NAMESPACE && !$this->isKeyword($type); }
Detects whether the given type represents a relative structural element name. @param string $type A relative or absolute type as defined in the phpDocumentor documentation. @psalm-mutation-free
isPartialStructuralElementName
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function isFqsen(string $type) : bool { return strpos($type, self::OPERATOR_NAMESPACE) === 0; }
Tests whether the given type is a Fully Qualified Structural Element Name. @psalm-mutation-free
isFqsen
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function resolveKeyword(string $type) : Type { $className = $this->keywords[strtolower($type)]; return new $className(); }
Resolves the given keyword (such as `string`) into a Type object representing that keyword. @psalm-mutation-free
resolveKeyword
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function resolveTypedObject(string $type, ?Context $context = null) : Object_ { return new Object_($this->fqsenResolver->resolve($type, $context)); }
Resolves the given FQSEN string into an FQSEN object. @psalm-mutation-free
resolveTypedObject
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
private function tryParseRemainingCompoundTypes(TokenIterator $tokenIterator, Context $context, Type $type) : Type { if ($tokenIterator->isCurrentTokenType(Lexer::TOKEN_UNION) || $tokenIterator->isCurrentTokenType(Lexer::TOKEN_INTERSECTION)) { Deprecation::trigger('phpdocumentor/type-resolver', 'https://github.com/phpDocumentor/TypeResolver/issues/184', 'Legacy nullable type detected, please update your code as you are using nullable types in a docblock. support will be removed in v2.0.0'); } $continue = \true; while ($continue) { $continue = \false; while ($tokenIterator->tryConsumeTokenType(Lexer::TOKEN_UNION)) { $ast = $this->parse($tokenIterator); $type2 = $this->createType($ast, $context); $type = new Compound([$type, $type2]); $continue = \true; } while ($tokenIterator->tryConsumeTokenType(Lexer::TOKEN_INTERSECTION)) { $ast = $this->typeParser->parse($tokenIterator); $type2 = $this->createType($ast, $context); $type = new Intersection([$type, $type2]); $continue = \true; } } return $type; }
Will try to parse unsupported type notations by phpstan The phpstan parser doesn't support the illegal nullable combinations like this library does. This method will warn the user about those notations but for bc purposes we will still have it here.
tryParseRemainingCompoundTypes
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/TypeResolver.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/TypeResolver.php
MIT
public function __toString() : string { return 'callable-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/CallableString.php
MIT
public function __toString() : string { return 'html-escaped-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/HtmlEscapedString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/HtmlEscapedString.php
MIT
public function __toString() : string { return 'int<' . $this->minValue . ', ' . $this->maxValue . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/IntegerRange.php
MIT
public function __toString() : string { if ($this->valueType instanceof Mixed_) { return 'list'; } return 'list<' . $this->valueType . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/List_.php
MIT
public function __toString() : string { return 'literal-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/LiteralString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LiteralString.php
MIT
public function __toString() : string { return 'lowercase-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/LowercaseString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/LowercaseString.php
MIT
public function __toString() : string { return 'negative-int'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NegativeInteger.php
MIT
public function __toString() : string { if ($this->keyType) { return 'non-empty-array<' . $this->keyType . ',' . $this->valueType . '>'; } if ($this->valueType instanceof Mixed_) { return 'non-empty-array'; } return 'non-empty-array<' . $this->valueType . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyArray.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyArray.php
MIT
public function __toString() : string { if ($this->valueType instanceof Mixed_) { return 'non-empty-list'; } return 'non-empty-list<' . $this->valueType . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyList.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyList.php
MIT
public function __toString() : string { return 'non-empty-lowercase-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyLowercaseString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyLowercaseString.php
MIT
public function __toString() : string { return 'non-empty-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NonEmptyString.php
MIT
public function __toString() : string { return 'numeric-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/NumericString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/NumericString.php
MIT
public function __toString() : string { return 'numeric'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/Numeric_.php
MIT
public function __toString() : string { return 'positive-int'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/PositiveInteger.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/PositiveInteger.php
MIT
public function __toString() : string { return 'trait-string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/PseudoTypes/TraitString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/PseudoTypes/TraitString.php
MIT
public function __construct(?Type $valueType = null, ?Type $keyType = null) { if ($valueType === null) { $valueType = new Mixed_(); } $this->valueType = $valueType; $this->defaultKeyType = new Compound([new String_(), new Integer()]); $this->keyType = $keyType; }
Initializes this representation of an array with the given Type.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
MIT
public function getKeyType() : Type { return $this->keyType ?? $this->defaultKeyType; }
Returns the type for the keys of this array.
getKeyType
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
MIT
public function getValueType() : Type { return $this->valueType; }
Returns the type for the values of this array.
getValueType
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
MIT
public function __toString() : string { if ($this->keyType) { return 'array<' . $this->keyType . ',' . $this->valueType . '>'; } if ($this->valueType instanceof Mixed_) { return 'array'; } if ($this->valueType instanceof Compound) { return '(' . $this->valueType . ')[]'; } return $this->valueType . '[]'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AbstractList.php
MIT
public function get(int $index) : ?Type { if (!$this->has($index)) { return null; } return $this->types[$index]; }
Returns the type at the given index.
get
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
MIT
public function has(int $index) : bool { return array_key_exists($index, $this->types); }
Tests if this compound type has a type with the given index.
has
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
MIT
public function contains(Type $type) : bool { foreach ($this->types as $typePart) { // if the type is duplicate; do not add it if ((string) $typePart === (string) $type) { return \true; } } return \false; }
Tests if this compound type contains the given type.
contains
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
MIT
public function __toString() : string { return implode($this->token, $this->types); }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/AggregatedType.php
MIT
public function __toString() : string { return 'bool'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Boolean.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Boolean.php
MIT
public function __toString() : string { return 'callable'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Callable_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Callable_.php
MIT
public function __construct(?Fqsen $fqsen = null) { $this->fqsen = $fqsen; }
Initializes this representation of a class string with the given Fqsen.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
MIT
public function getFqsen() : ?Fqsen { return $this->fqsen; }
Returns the FQSEN associated with this object.
getFqsen
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
MIT
public function __toString() : string { if ($this->fqsen === null) { return 'class-string'; } return 'class-string<' . (string) $this->fqsen . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ClassString.php
MIT
public function __construct(?Fqsen $fqsen, Type $valueType, ?Type $keyType = null) { parent::__construct($valueType, $keyType); $this->fqsen = $fqsen; }
Initializes this representation of an array with the given Type or Fqsen.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Collection.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Collection.php
MIT
public function getFqsen() : ?Fqsen { return $this->fqsen; }
Returns the FQSEN associated with this object.
getFqsen
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Collection.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Collection.php
MIT
public function __toString() : string { $objectType = (string) ($this->fqsen ?? 'object'); if ($this->keyType === null) { return $objectType . '<' . $this->valueType . '>'; } return $objectType . '<' . $this->keyType . ',' . $this->valueType . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Collection.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Collection.php
MIT
public function __construct(array $types) { parent::__construct($types, '|'); }
Initializes a compound type (i.e. `string|int`) and tests if the provided types all implement the Type interface. @param array<Type> $types
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Compound.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Compound.php
MIT
public function __construct(string $namespace, array $namespaceAliases = []) { $this->namespace = $namespace !== 'global' && $namespace !== 'default' ? trim($namespace, '\\') : ''; foreach ($namespaceAliases as $alias => $fqnn) { if ($fqnn[0] === '\\') { $fqnn = substr($fqnn, 1); } if ($fqnn[strlen($fqnn) - 1] === '\\') { $fqnn = substr($fqnn, 0, -1); } $namespaceAliases[$alias] = $fqnn; } $this->namespaceAliases = $namespaceAliases; }
Initializes the new context and normalizes all passed namespaces to be in Qualified Namespace Name (QNN) format (without a preceding `\`). @param string $namespace The namespace where this DocBlock resides in. @param string[] $namespaceAliases List of namespace aliases => Fully Qualified Namespace. @psalm-param array<string, string> $namespaceAliases
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Context.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Context.php
MIT
public function getNamespace() : string { return $this->namespace; }
Returns the Qualified Namespace Name (thus without `\` in front) where the associated element is in.
getNamespace
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Context.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Context.php
MIT
public function getNamespaceAliases() : array { return $this->namespaceAliases; }
Returns a list of Qualified Namespace Names (thus without `\` in front) that are imported, the keys represent the alias for the imported Namespace. @return string[] @psalm-return array<string, string>
getNamespaceAliases
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Context.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Context.php
MIT
public function createFromReflector(Reflector $reflector) : Context { if ($reflector instanceof ReflectionClass) { //phpcs:ignore SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration.MissingVariable /** @var ReflectionClass<object> $reflector */ return $this->createFromReflectionClass($reflector); } if ($reflector instanceof ReflectionParameter) { return $this->createFromReflectionParameter($reflector); } if ($reflector instanceof ReflectionMethod) { return $this->createFromReflectionMethod($reflector); } if ($reflector instanceof ReflectionProperty) { return $this->createFromReflectionProperty($reflector); } if ($reflector instanceof ReflectionClassConstant) { return $this->createFromReflectionClassConstant($reflector); } throw new UnexpectedValueException('Unhandled \\Reflector instance given: ' . get_class($reflector)); }
Build a Context given a Class Reflection. @see Context for more information on Contexts.
createFromReflector
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
public function createForNamespace(string $namespace, string $fileContents) : Context { $namespace = trim($namespace, '\\'); $useStatements = []; $currentNamespace = ''; $tokens = new ArrayIterator(token_get_all($fileContents)); while ($tokens->valid()) { $currentToken = $tokens->current(); switch ($currentToken[0]) { case T_NAMESPACE: $currentNamespace = $this->parseNamespace($tokens); break; case T_CLASS: case T_TRAIT: // Fast-forward the iterator through the class so that any // T_USE tokens found within are skipped - these are not // valid namespace use statements so should be ignored. $braceLevel = 0; $firstBraceFound = \false; while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) { $currentToken = $tokens->current(); if ($currentToken === '{' || in_array($currentToken[0], [T_CURLY_OPEN, T_DOLLAR_OPEN_CURLY_BRACES], \true)) { if (!$firstBraceFound) { $firstBraceFound = \true; } ++$braceLevel; } if ($currentToken === '}') { --$braceLevel; } $tokens->next(); } break; case T_USE: if ($currentNamespace === $namespace) { $useStatements += $this->parseUseStatement($tokens); } break; } $tokens->next(); } return new Context($namespace, $useStatements); }
Build a Context for a namespace in the provided file contents. @see Context for more information on Contexts. @param string $namespace It does not matter if a `\` precedes the namespace name, this method first normalizes. @param string $fileContents The file's contents to retrieve the aliases from with the given namespace.
createForNamespace
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
private function parseNamespace(ArrayIterator $tokens) : string { // skip to the first string or namespace separator $this->skipToNextStringOrNamespaceSeparator($tokens); $name = ''; $acceptedTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED]; while ($tokens->valid() && in_array($tokens->current()[0], $acceptedTokens, \true)) { $name .= $tokens->current()[1]; $tokens->next(); } return $name; }
Deduce the name from tokens when we are at the T_NAMESPACE token. @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
parseNamespace
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
private function parseUseStatement(ArrayIterator $tokens) : array { $uses = []; while ($tokens->valid()) { $this->skipToNextStringOrNamespaceSeparator($tokens); $uses += $this->extractUseStatements($tokens); $currentToken = $tokens->current(); if ($currentToken[0] === self::T_LITERAL_END_OF_USE) { return $uses; } } return $uses; }
Deduce the names of all imports when we are at the T_USE token. @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens @return string[] @psalm-return array<string, string>
parseUseStatement
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
private function skipToNextStringOrNamespaceSeparator(ArrayIterator $tokens) : void { while ($tokens->valid()) { $currentToken = $tokens->current(); if (in_array($currentToken[0], [T_STRING, T_NS_SEPARATOR], \true)) { break; } if ($currentToken[0] === T_NAME_QUALIFIED) { break; } if (defined('T_NAME_FULLY_QUALIFIED') && $currentToken[0] === T_NAME_FULLY_QUALIFIED) { break; } $tokens->next(); } }
Fast-forwards the iterator as longs as we don't encounter a T_STRING or T_NS_SEPARATOR token. @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens
skipToNextStringOrNamespaceSeparator
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
private function extractUseStatements(ArrayIterator $tokens) : array { $extractedUseStatements = []; $groupedNs = ''; $currentNs = ''; $currentAlias = ''; $state = 'start'; while ($tokens->valid()) { $currentToken = $tokens->current(); $tokenId = is_string($currentToken) ? $currentToken : $currentToken[0]; $tokenValue = is_string($currentToken) ? null : $currentToken[1]; switch ($state) { case 'start': switch ($tokenId) { case T_STRING: case T_NS_SEPARATOR: $currentNs .= (string) $tokenValue; $currentAlias = $tokenValue; break; case T_NAME_QUALIFIED: case T_NAME_FULLY_QUALIFIED: $currentNs .= (string) $tokenValue; $currentAlias = substr((string) $tokenValue, (int) strrpos((string) $tokenValue, '\\') + 1); break; case T_CURLY_OPEN: case '{': $state = 'grouped'; $groupedNs = $currentNs; break; case T_AS: $state = 'start-alias'; break; case self::T_LITERAL_USE_SEPARATOR: case self::T_LITERAL_END_OF_USE: $state = 'end'; break; default: break; } break; case 'start-alias': switch ($tokenId) { case T_STRING: $currentAlias = $tokenValue; break; case self::T_LITERAL_USE_SEPARATOR: case self::T_LITERAL_END_OF_USE: $state = 'end'; break; default: break; } break; case 'grouped': switch ($tokenId) { case T_STRING: case T_NS_SEPARATOR: $currentNs .= (string) $tokenValue; $currentAlias = $tokenValue; break; case T_AS: $state = 'grouped-alias'; break; case self::T_LITERAL_USE_SEPARATOR: $state = 'grouped'; $extractedUseStatements[(string) $currentAlias] = $currentNs; $currentNs = $groupedNs; $currentAlias = ''; break; case self::T_LITERAL_END_OF_USE: $state = 'end'; break; default: break; } break; case 'grouped-alias': switch ($tokenId) { case T_STRING: $currentAlias = $tokenValue; break; case self::T_LITERAL_USE_SEPARATOR: $state = 'grouped'; $extractedUseStatements[(string) $currentAlias] = $currentNs; $currentNs = $groupedNs; $currentAlias = ''; break; case self::T_LITERAL_END_OF_USE: $state = 'end'; break; default: break; } } if ($state === 'end') { break; } $tokens->next(); } if ($groupedNs !== $currentNs) { $extractedUseStatements[(string) $currentAlias] = $currentNs; } return $extractedUseStatements; }
Deduce the namespace name and alias of an import when we are at the T_USE token or have not reached the end of a USE statement yet. This will return a key/value array of the alias => namespace. @param ArrayIterator<int, string|array{0:int,1:string,2:int}> $tokens @return string[] @psalm-return array<string, string> @psalm-suppress TypeDoesNotContainType
extractUseStatements
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/ContextFactory.php
MIT
public function __construct(Type $valueType) { $this->valueType = $valueType; }
Initializes this representation of an array with the given Type.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Expression.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Expression.php
MIT
public function getValueType() : Type { return $this->valueType; }
Returns the value for the keys of this array.
getValueType
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Expression.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Expression.php
MIT
public function __toString() : string { return '(' . $this->valueType . ')'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Expression.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Expression.php
MIT
public function __toString() : string { return 'float'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Float_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Float_.php
MIT
public function __toString() : string { return 'int'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Integer.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Integer.php
MIT
public function __construct(?Fqsen $fqsen = null) { $this->fqsen = $fqsen; }
Initializes this representation of a class string with the given Fqsen.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
MIT
public function getFqsen() : ?Fqsen { return $this->fqsen; }
Returns the FQSEN associated with this object.
getFqsen
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
MIT
public function __toString() : string { if ($this->fqsen === null) { return 'interface-string'; } return 'interface-string<' . (string) $this->fqsen . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/InterfaceString.php
MIT
public function __construct(array $types) { parent::__construct($types, '&'); }
Initializes a intersection type (i.e. `\A&\B`) and tests if the provided types all implement the Type interface. @param array<Type> $types
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Intersection.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Intersection.php
MIT
public function __toString() : string { if ($this->keyType) { return 'iterable<' . $this->keyType . ',' . $this->valueType . '>'; } if ($this->valueType instanceof Mixed_) { return 'iterable'; } return 'iterable<' . $this->valueType . '>'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Iterable_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Iterable_.php
MIT
public function __toString() : string { return 'mixed'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Mixed_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Mixed_.php
MIT
public function __toString() : string { return 'never'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Never_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Never_.php
MIT
public function __construct(Type $realType) { $this->realType = $realType; }
Initialises this nullable type using the real type embedded
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
MIT
public function getActualType() : Type { return $this->realType; }
Provide access to the actual type directly, if needed.
getActualType
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
MIT
public function __toString() : string { return '?' . $this->realType->__toString(); }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Nullable.php
MIT
public function __toString() : string { return 'null'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Null_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Null_.php
MIT
public function __construct(?Fqsen $fqsen = null) { if (strpos((string) $fqsen, '::') !== \false || strpos((string) $fqsen, '()') !== \false) { throw new InvalidArgumentException('Object types can only refer to a class, interface or trait but a method, function, constant or ' . 'property was received: ' . (string) $fqsen); } $this->fqsen = $fqsen; }
Initializes this object with an optional FQSEN, if not provided this object is considered 'untyped'. @throws InvalidArgumentException When provided $fqsen is not a valid type.
__construct
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Object_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Object_.php
MIT
public function getFqsen() : ?Fqsen { return $this->fqsen; }
Returns the FQSEN associated with this object.
getFqsen
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Object_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Object_.php
MIT
public function __toString() : string { return 'parent'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Parent_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Parent_.php
MIT
public function __toString() : string { return 'resource'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Resource_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Resource_.php
MIT
public function __toString() : string { return 'scalar'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Scalar.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Scalar.php
MIT
public function __toString() : string { return 'self'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Self_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Self_.php
MIT
public function __toString() : string { return 'static'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Static_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Static_.php
MIT
public function __toString() : string { return 'string'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/String_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/String_.php
MIT
public function __toString() : string { return '$this'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/This.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/This.php
MIT
public function __toString() : string { return 'void'; }
Returns a rendered output of the Type as it would be used in a DocBlock.
__toString
php
deptrac/deptrac
vendor/phpdocumentor/type-resolver/src/Types/Void_.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpdocumentor/type-resolver/src/Types/Void_.php
MIT
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; }
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/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
MIT
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 a node. @param Node $node Node to traverse. @return Node Result of traversal (may be original node or new one)
traverseNode
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
MIT
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; }
Recursively traverse array (usually of nodes). @param mixed[] $nodes Array to traverse @return mixed[] Result of traversal (may be original array or changed one)
traverseArray
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/NodeTraverser.php
MIT
public function __construct(bool $isStatic, ?TypeNode $returnType, string $methodName, array $parameters, string $description, array $templateTypes = []) { $this->isStatic = $isStatic; $this->returnType = $returnType; $this->methodName = $methodName; $this->parameters = $parameters; $this->description = $description; $this->templateTypes = $templateTypes; }
@param MethodTagValueParameterNode[] $parameters @param TemplateTagValueNode[] $templateTypes
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueNode.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/MethodTagValueNode.php
MIT
public function __construct($key, $value) { $this->key = $key; $this->value = $value; }
@param KeyType $key @param ValueType $value
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/Doctrine/DoctrineArrayItem.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/PhpDoc/Doctrine/DoctrineArrayItem.php
MIT
public function __construct($keyName, bool $optional, TypeNode $valueType) { $this->keyName = $keyName; $this->optional = $optional; $this->valueType = $valueType; }
@param ConstExprIntegerNode|ConstExprStringNode|IdentifierTypeNode|null $keyName
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeItemNode.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeItemNode.php
MIT
public function __construct(array $items, bool $sealed = \true, string $kind = self::KIND_ARRAY, ?ArrayShapeUnsealedTypeNode $unsealedType = null) { $this->items = $items; $this->sealed = $sealed; $this->kind = $kind; $this->unsealedType = $unsealedType; }
@param ArrayShapeItemNode[] $items @param self::KIND_* $kind
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeNode.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/Type/ArrayShapeNode.php
MIT
public function __construct(IdentifierTypeNode $identifier, array $parameters, TypeNode $returnType, array $templateTypes = []) { $this->identifier = $identifier; $this->parameters = $parameters; $this->returnType = $returnType; $this->templateTypes = $templateTypes; }
@param CallableTypeParameterNode[] $parameters @param TemplateTagValueNode[] $templateTypes
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeNode.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/Type/CallableTypeNode.php
MIT
public function __construct(IdentifierTypeNode $type, array $genericTypes, array $variances = []) { $this->type = $type; $this->genericTypes = $genericTypes; $this->variances = $variances; }
@param TypeNode[] $genericTypes @param (self::VARIANCE_*)[] $variances
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Ast/Type/GenericTypeNode.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Ast/Type/GenericTypeNode.php
MIT
public function tokenize(string $s) : array { if ($this->regexp === null) { $this->regexp = $this->generateRegexp(); } preg_match_all($this->regexp, $s, $matches, PREG_SET_ORDER); $tokens = []; $line = 1; foreach ($matches as $match) { $type = (int) $match['MARK']; $tokens[] = [$match[0], $type, $line]; if ($type !== self::TOKEN_PHPDOC_EOL) { continue; } $line++; } $tokens[] = ['', self::TOKEN_END, $line]; return $tokens; }
@return list<array{string, int, int}>
tokenize
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Lexer/Lexer.php
MIT
public function __construct(bool $unescapeStrings = \false, bool $quoteAwareConstExprString = \false, array $usedAttributes = []) { $this->unescapeStrings = $unescapeStrings; $this->quoteAwareConstExprString = $quoteAwareConstExprString; $this->useLinesAttributes = $usedAttributes['lines'] ?? \false; $this->useIndexAttributes = $usedAttributes['indexes'] ?? \false; $this->parseDoctrineStrings = \false; }
@param array{lines?: bool, indexes?: bool} $usedAttributes
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
MIT
public function parseDoctrineString(string $text, TokenIterator $tokens) : Ast\ConstExpr\DoctrineConstExprStringNode { // Because of how Lexer works, a valid Doctrine string // can consist of a sequence of TOKEN_DOUBLE_QUOTED_STRING and TOKEN_DOCTRINE_ANNOTATION_STRING while ($tokens->isCurrentTokenType(Lexer::TOKEN_DOUBLE_QUOTED_STRING, Lexer::TOKEN_DOCTRINE_ANNOTATION_STRING)) { $text .= $tokens->currentTokenValue(); $tokens->next(); } return new Ast\ConstExpr\DoctrineConstExprStringNode(Ast\ConstExpr\DoctrineConstExprStringNode::unescape($text)); }
This method is supposed to be called with TokenIterator after reading TOKEN_DOUBLE_QUOTED_STRING and shifting to the next token.
parseDoctrineString
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
MIT
private function enrichWithAttributes(TokenIterator $tokens, Ast\ConstExpr\ConstExprNode $node, int $startLine, int $startIndex) : Ast\ConstExpr\ConstExprNode { if ($this->useLinesAttributes) { $node->setAttribute(Ast\Attribute::START_LINE, $startLine); $node->setAttribute(Ast\Attribute::END_LINE, $tokens->currentTokenLine()); } if ($this->useIndexAttributes) { $node->setAttribute(Ast\Attribute::START_INDEX, $startIndex); $node->setAttribute(Ast\Attribute::END_INDEX, $tokens->endIndexOfLastRelevantToken()); } return $node; }
@template T of Ast\ConstExpr\ConstExprNode @param T $node @return T
enrichWithAttributes
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/ConstExprParser.php
MIT
public function __construct(TypeParser $typeParser, ConstExprParser $constantExprParser, bool $requireWhitespaceBeforeDescription = \false, bool $preserveTypeAliasesWithInvalidTypes = \false, array $usedAttributes = [], bool $parseDoctrineAnnotations = \false, bool $textBetweenTagsBelongsToDescription = \false) { $this->typeParser = $typeParser; $this->constantExprParser = $constantExprParser; $this->doctrineConstantExprParser = $constantExprParser->toDoctrine(); $this->requireWhitespaceBeforeDescription = $requireWhitespaceBeforeDescription; $this->preserveTypeAliasesWithInvalidTypes = $preserveTypeAliasesWithInvalidTypes; $this->parseDoctrineAnnotations = $parseDoctrineAnnotations; $this->useLinesAttributes = $usedAttributes['lines'] ?? \false; $this->useIndexAttributes = $usedAttributes['indexes'] ?? \false; $this->textBetweenTagsBelongsToDescription = $textBetweenTagsBelongsToDescription; }
@param array{lines?: bool, indexes?: bool} $usedAttributes
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
MIT
private function enrichWithAttributes(TokenIterator $tokens, Ast\Node $tag, int $startLine, int $startIndex) : Ast\Node { if ($this->useLinesAttributes) { $tag->setAttribute(Ast\Attribute::START_LINE, $startLine); $tag->setAttribute(Ast\Attribute::END_LINE, $tokens->currentTokenLine()); } if ($this->useIndexAttributes) { $tag->setAttribute(Ast\Attribute::START_INDEX, $startIndex); $tag->setAttribute(Ast\Attribute::END_INDEX, $tokens->endIndexOfLastRelevantToken()); } return $tag; }
@template T of Ast\Node @param T $tag @return T
enrichWithAttributes
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
MIT
private function parseParamTagValue(TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagValueNode { if ($tokens->isCurrentTokenType(Lexer::TOKEN_REFERENCE, Lexer::TOKEN_VARIADIC, Lexer::TOKEN_VARIABLE)) { $type = null; } else { $type = $this->typeParser->parse($tokens); } $isReference = $tokens->tryConsumeTokenType(Lexer::TOKEN_REFERENCE); $isVariadic = $tokens->tryConsumeTokenType(Lexer::TOKEN_VARIADIC); $parameterName = $this->parseRequiredVariableName($tokens); $description = $this->parseOptionalDescription($tokens); if ($type !== null) { return new Ast\PhpDoc\ParamTagValueNode($type, $isVariadic, $parameterName, $description, $isReference); } return new Ast\PhpDoc\TypelessParamTagValueNode($isVariadic, $parameterName, $description, $isReference); }
@return Ast\PhpDoc\ParamTagValueNode|Ast\PhpDoc\TypelessParamTagValueNode
parseParamTagValue
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
MIT
private function parseAssertTagValue(TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagValueNode { $isNegated = $tokens->tryConsumeTokenType(Lexer::TOKEN_NEGATED); $isEquality = $tokens->tryConsumeTokenType(Lexer::TOKEN_EQUAL); $type = $this->typeParser->parse($tokens); $parameter = $this->parseAssertParameter($tokens); $description = $this->parseOptionalDescription($tokens); if (array_key_exists('method', $parameter)) { return new Ast\PhpDoc\AssertTagMethodValueNode($type, $parameter['parameter'], $parameter['method'], $isNegated, $description, $isEquality); } elseif (array_key_exists('property', $parameter)) { return new Ast\PhpDoc\AssertTagPropertyValueNode($type, $parameter['parameter'], $parameter['property'], $isNegated, $description, $isEquality); } return new Ast\PhpDoc\AssertTagValueNode($type, $parameter['parameter'], $isNegated, $description, $isEquality); }
@return Ast\PhpDoc\AssertTagValueNode|Ast\PhpDoc\AssertTagPropertyValueNode|Ast\PhpDoc\AssertTagMethodValueNode
parseAssertTagValue
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
MIT
private function parseAssertParameter(TokenIterator $tokens) : array { if ($tokens->isCurrentTokenType(Lexer::TOKEN_THIS_VARIABLE)) { $parameter = '$this'; $tokens->next(); } else { $parameter = $tokens->currentTokenValue(); $tokens->consumeTokenType(Lexer::TOKEN_VARIABLE); } if ($tokens->isCurrentTokenType(Lexer::TOKEN_ARROW)) { $tokens->consumeTokenType(Lexer::TOKEN_ARROW); $propertyOrMethod = $tokens->currentTokenValue(); $tokens->consumeTokenType(Lexer::TOKEN_IDENTIFIER); if ($tokens->tryConsumeTokenType(Lexer::TOKEN_OPEN_PARENTHESES)) { $tokens->consumeTokenType(Lexer::TOKEN_CLOSE_PARENTHESES); return ['parameter' => $parameter, 'method' => $propertyOrMethod]; } return ['parameter' => $parameter, 'property' => $propertyOrMethod]; } return ['parameter' => $parameter]; }
@return array{parameter: string}|array{parameter: string, property: string}|array{parameter: string, method: string}
parseAssertParameter
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/PhpDocParser.php
MIT
private static function parseEscapeSequences(string $str, string $quote) : string { $str = str_replace('\\' . $quote, $quote, $str); return preg_replace_callback('~\\\\([\\\\nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}|u\\{([0-9a-fA-F]+)\\})~', static function ($matches) { $str = $matches[1]; if (isset(self::REPLACEMENTS[$str])) { return self::REPLACEMENTS[$str]; } if ($str[0] === 'x' || $str[0] === 'X') { return chr((int) hexdec(substr($str, 1))); } if ($str[0] === 'u') { if (!isset($matches[2])) { throw new ShouldNotHappenException(); } return self::codePointToUtf8((int) hexdec($matches[2])); } return chr((int) octdec($str)); }, $str); }
Implementation based on https://github.com/nikic/PHP-Parser/blob/b0edd4c41111042d43bb45c6c657b2e0db367d9e/lib/PhpParser/Node/Scalar/String_.php#L90-L130
parseEscapeSequences
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/StringUnescaper.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/StringUnescaper.php
MIT
public function __construct(array $tokens, int $index = 0) { $this->tokens = $tokens; $this->index = $index; $this->skipIrrelevantTokens(); }
@param list<array{string, int, int}> $tokens
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
MIT
public function getTokens() : array { return $this->tokens; }
@return list<array{string, int, int}>
getTokens
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
MIT
public function hasTokenImmediatelyBefore(int $pos, int $expectedTokenType) : bool { $tokens = $this->tokens; $pos--; for (; $pos >= 0; $pos--) { $token = $tokens[$pos]; $type = $token[Lexer::TYPE_OFFSET]; if ($type === $expectedTokenType) { return \true; } if (!in_array($type, [Lexer::TOKEN_HORIZONTAL_WS, Lexer::TOKEN_PHPDOC_EOL], \true)) { break; } } return \false; }
Check whether the position is directly preceded by a certain token type. During this check TOKEN_HORIZONTAL_WS and TOKEN_PHPDOC_EOL are skipped
hasTokenImmediatelyBefore
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
MIT
public function hasTokenImmediatelyAfter(int $pos, int $expectedTokenType) : bool { $tokens = $this->tokens; $pos++; for ($c = count($tokens); $pos < $c; $pos++) { $token = $tokens[$pos]; $type = $token[Lexer::TYPE_OFFSET]; if ($type === $expectedTokenType) { return \true; } if (!in_array($type, [Lexer::TOKEN_HORIZONTAL_WS, Lexer::TOKEN_PHPDOC_EOL], \true)) { break; } } return \false; }
Check whether the position is directly followed by a certain token type. During this check TOKEN_HORIZONTAL_WS and TOKEN_PHPDOC_EOL are skipped
hasTokenImmediatelyAfter
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
MIT
public function hasParentheses(int $startPos, int $endPos) : bool { return $this->hasTokenImmediatelyBefore($startPos, Lexer::TOKEN_OPEN_PARENTHESES) && $this->hasTokenImmediatelyAfter($endPos, Lexer::TOKEN_CLOSE_PARENTHESES); }
Whether the given position is immediately surrounded by parenthesis.
hasParentheses
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TokenIterator.php
MIT
public function __construct(?ConstExprParser $constExprParser = null, bool $quoteAwareConstExprString = \false, array $usedAttributes = []) { $this->constExprParser = $constExprParser; $this->quoteAwareConstExprString = $quoteAwareConstExprString; $this->useLinesAttributes = $usedAttributes['lines'] ?? \false; $this->useIndexAttributes = $usedAttributes['indexes'] ?? \false; }
@param array{lines?: bool, indexes?: bool} $usedAttributes
__construct
php
deptrac/deptrac
vendor/phpstan/phpdoc-parser/src/Parser/TypeParser.php
https://github.com/deptrac/deptrac/blob/master/vendor/phpstan/phpdoc-parser/src/Parser/TypeParser.php
MIT