mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-16 22:58:15 +01:00
Add missing return types
This commit is contained in:
parent
43d6332dce
commit
48f470eac7
@ -94,7 +94,7 @@ class #(-p) extends \PhpParser\ParserAbstract
|
||||
);
|
||||
#endif
|
||||
|
||||
protected function initReduceCallbacks() {
|
||||
protected function initReduceCallbacks(): void {
|
||||
$this->reduceCallbacks = [
|
||||
#reduce
|
||||
%n => function ($stackPos) {
|
||||
|
@ -83,6 +83,11 @@ class Class_ extends Declaration {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the class readonly.
|
||||
*
|
||||
* @return $this The builder instance (for fluid interface)
|
||||
*/
|
||||
public function makeReadonly() {
|
||||
$this->flags = BuilderHelpers::addClassModifier($this->flags, Modifiers::READONLY);
|
||||
|
||||
|
@ -114,7 +114,7 @@ class TraitUseAdaptation implements Builder {
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function setModifier(int $modifier) {
|
||||
protected function setModifier(int $modifier): void {
|
||||
if ($this->type === self::TYPE_UNDEFINED) {
|
||||
$this->type = self::TYPE_ALIAS;
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ class ConstExprEvaluator {
|
||||
return $this->evaluate($expr);
|
||||
}
|
||||
|
||||
/** @return mixed */
|
||||
private function evaluate(Expr $expr) {
|
||||
if ($expr instanceof Scalar\Int_
|
||||
|| $expr instanceof Scalar\Float_
|
||||
@ -146,7 +147,7 @@ class ConstExprEvaluator {
|
||||
return ($this->fallbackEvaluator)($expr);
|
||||
}
|
||||
|
||||
private function evaluateArray(Expr\Array_ $expr) {
|
||||
private function evaluateArray(Expr\Array_ $expr): array {
|
||||
$array = [];
|
||||
foreach ($expr->items as $item) {
|
||||
if (null !== $item->key) {
|
||||
@ -160,6 +161,7 @@ class ConstExprEvaluator {
|
||||
return $array;
|
||||
}
|
||||
|
||||
/** @return mixed */
|
||||
private function evaluateTernary(Expr\Ternary $expr) {
|
||||
if (null === $expr->if) {
|
||||
return $this->evaluate($expr->cond) ?: $this->evaluate($expr->else);
|
||||
@ -170,6 +172,7 @@ class ConstExprEvaluator {
|
||||
: $this->evaluate($expr->else);
|
||||
}
|
||||
|
||||
/** @return mixed */
|
||||
private function evaluateBinaryOp(Expr\BinaryOp $expr) {
|
||||
if ($expr instanceof Expr\BinaryOp\Coalesce
|
||||
&& $expr->left instanceof Expr\ArrayDimFetch
|
||||
@ -216,6 +219,7 @@ class ConstExprEvaluator {
|
||||
throw new \Exception('Should not happen');
|
||||
}
|
||||
|
||||
/** @return mixed */
|
||||
private function evaluateConstFetch(Expr\ConstFetch $expr) {
|
||||
$name = $expr->name->toLowerString();
|
||||
switch ($name) {
|
||||
|
@ -64,7 +64,7 @@ class Error extends \RuntimeException {
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function setAttributes(array $attributes) {
|
||||
public function setAttributes(array $attributes): void {
|
||||
$this->attributes = $attributes;
|
||||
$this->updateMessage();
|
||||
}
|
||||
@ -74,7 +74,7 @@ class Error extends \RuntimeException {
|
||||
*
|
||||
* @param string $message Error message
|
||||
*/
|
||||
public function setRawMessage(string $message) {
|
||||
public function setRawMessage(string $message): void {
|
||||
$this->rawMessage = $message;
|
||||
$this->updateMessage();
|
||||
}
|
||||
@ -84,7 +84,7 @@ class Error extends \RuntimeException {
|
||||
*
|
||||
* @param int $line Error start line
|
||||
*/
|
||||
public function setStartLine(int $line) {
|
||||
public function setStartLine(int $line): void {
|
||||
$this->attributes['startLine'] = $line;
|
||||
$this->updateMessage();
|
||||
}
|
||||
@ -167,7 +167,7 @@ class Error extends \RuntimeException {
|
||||
/**
|
||||
* Updates the exception message after a change to rawMessage or rawLine.
|
||||
*/
|
||||
protected function updateMessage() {
|
||||
protected function updateMessage(): void {
|
||||
$this->message = $this->rawMessage;
|
||||
|
||||
if (-1 === $this->getStartLine()) {
|
||||
|
@ -8,5 +8,5 @@ interface ErrorHandler {
|
||||
*
|
||||
* @param Error $error The error that needs to be handled
|
||||
*/
|
||||
public function handleError(Error $error);
|
||||
public function handleError(Error $error): void;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class Collecting implements ErrorHandler {
|
||||
/** @var Error[] Collected errors */
|
||||
private $errors = [];
|
||||
|
||||
public function handleError(Error $error) {
|
||||
public function handleError(Error $error): void {
|
||||
$this->errors[] = $error;
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ class Collecting implements ErrorHandler {
|
||||
/**
|
||||
* Reset/clear collected errors.
|
||||
*/
|
||||
public function clearErrors() {
|
||||
public function clearErrors(): void {
|
||||
$this->errors = [];
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ use PhpParser\ErrorHandler;
|
||||
* This is the default strategy used by all components.
|
||||
*/
|
||||
class Throwing implements ErrorHandler {
|
||||
public function handleError(Error $error) {
|
||||
public function handleError(Error $error): void {
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class Differ {
|
||||
return $this->coalesceReplacements($this->diff($old, $new));
|
||||
}
|
||||
|
||||
private function calculateTrace(array $a, array $b) {
|
||||
private function calculateTrace(array $a, array $b): array {
|
||||
$n = \count($a);
|
||||
$m = \count($b);
|
||||
$max = $n + $m;
|
||||
@ -80,7 +80,7 @@ class Differ {
|
||||
throw new \Exception('Should not happen');
|
||||
}
|
||||
|
||||
private function extractDiff(array $trace, int $x, int $y, array $a, array $b) {
|
||||
private function extractDiff(array $trace, int $x, int $y, array $a, array $b): array {
|
||||
$result = [];
|
||||
for ($d = \count($trace) - 1; $d >= 0; $d--) {
|
||||
$v = $trace[$d];
|
||||
|
@ -39,7 +39,7 @@ class PrintableNewAnonClassNode extends Expr {
|
||||
$this->stmts = $stmts;
|
||||
}
|
||||
|
||||
public static function fromNewNode(Expr\New_ $newNode) {
|
||||
public static function fromNewNode(Expr\New_ $newNode): self {
|
||||
$class = $newNode->class;
|
||||
assert($class instanceof Node\Stmt\Class_);
|
||||
// We don't assert that $class->name is null here, to allow consumers to assign unique names
|
||||
|
@ -103,7 +103,7 @@ class TokenStream {
|
||||
}
|
||||
|
||||
/** @param int|string|array $skipTokenType */
|
||||
public function skipLeft(int $pos, $skipTokenType) {
|
||||
public function skipLeft(int $pos, $skipTokenType): int {
|
||||
$tokens = $this->tokens;
|
||||
|
||||
$pos = $this->skipLeftWhitespace($pos);
|
||||
@ -121,7 +121,7 @@ class TokenStream {
|
||||
}
|
||||
|
||||
/** @param int|string|array $skipTokenType */
|
||||
public function skipRight(int $pos, $skipTokenType) {
|
||||
public function skipRight(int $pos, $skipTokenType): int {
|
||||
$tokens = $this->tokens;
|
||||
|
||||
$pos = $this->skipRightWhitespace($pos);
|
||||
@ -171,7 +171,7 @@ class TokenStream {
|
||||
}
|
||||
|
||||
/** @param int|string|array $findTokenType */
|
||||
public function findRight(int $pos, $findTokenType) {
|
||||
public function findRight(int $pos, $findTokenType): int {
|
||||
$tokens = $this->tokens;
|
||||
for ($count = \count($tokens); $pos < $count; $pos++) {
|
||||
if ($tokens[$pos]->is($findTokenType)) {
|
||||
@ -199,7 +199,7 @@ class TokenStream {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function haveBracesInRange(int $startPos, int $endPos) {
|
||||
public function haveBracesInRange(int $startPos, int $endPos): bool {
|
||||
return $this->haveTokenInRange($startPos, $endPos, '{')
|
||||
|| $this->haveTokenInRange($startPos, $endPos, T_CURLY_OPEN)
|
||||
|| $this->haveTokenInRange($startPos, $endPos, '}');
|
||||
|
@ -6,6 +6,7 @@ class JsonDecoder {
|
||||
/** @var \ReflectionClass[] Node type to reflection class map */
|
||||
private $reflectionClassCache;
|
||||
|
||||
/** @return mixed */
|
||||
public function decode(string $json) {
|
||||
$value = json_decode($json, true);
|
||||
if (json_last_error()) {
|
||||
@ -15,7 +16,10 @@ class JsonDecoder {
|
||||
return $this->decodeRecursive($value);
|
||||
}
|
||||
|
||||
/** @param mixed $value */
|
||||
/**
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
private function decodeRecursive($value) {
|
||||
if (\is_array($value)) {
|
||||
if (isset($value['nodeType'])) {
|
||||
|
@ -64,7 +64,7 @@ class Lexer {
|
||||
* @param ErrorHandler|null $errorHandler Error handler to use for lexing errors. Defaults to
|
||||
* ErrorHandler\Throwing
|
||||
*/
|
||||
public function startLexing(string $code, ?ErrorHandler $errorHandler = null) {
|
||||
public function startLexing(string $code, ?ErrorHandler $errorHandler = null): void {
|
||||
if (null === $errorHandler) {
|
||||
$errorHandler = new ErrorHandler\Throwing();
|
||||
}
|
||||
@ -111,7 +111,7 @@ class Lexer {
|
||||
&& substr($token->text, -2) !== '*/';
|
||||
}
|
||||
|
||||
protected function postprocessTokens(ErrorHandler $errorHandler) {
|
||||
protected function postprocessTokens(ErrorHandler $errorHandler): void {
|
||||
// This function reports errors (bad characters and unterminated comments) in the token
|
||||
// array, and performs certain canonicalizations:
|
||||
// * Use PHP 8.1 T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG and
|
||||
|
@ -72,7 +72,7 @@ class Emulative extends Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
public function startLexing(string $code, ?ErrorHandler $errorHandler = null) {
|
||||
public function startLexing(string $code, ?ErrorHandler $errorHandler = null): void {
|
||||
$emulators = array_filter($this->emulators, function ($emulator) use ($code) {
|
||||
return $emulator->isEmulationNeeded($code);
|
||||
});
|
||||
@ -116,7 +116,7 @@ class Emulative extends Lexer {
|
||||
&& $this->targetPhpVersion->older($emulatorPhpVersion);
|
||||
}
|
||||
|
||||
private function sortPatches() {
|
||||
private function sortPatches(): void {
|
||||
// Patches may be contributed by different emulators.
|
||||
// Make sure they are sorted by increasing patch position.
|
||||
usort($this->patches, function ($p1, $p2) {
|
||||
@ -124,7 +124,7 @@ class Emulative extends Lexer {
|
||||
});
|
||||
}
|
||||
|
||||
private function fixupTokens() {
|
||||
private function fixupTokens(): void {
|
||||
if (\count($this->patches) === 0) {
|
||||
return;
|
||||
}
|
||||
@ -191,7 +191,7 @@ class Emulative extends Lexer {
|
||||
*
|
||||
* @param Error[] $errors
|
||||
*/
|
||||
private function fixupErrors(array $errors) {
|
||||
private function fixupErrors(array $errors): void {
|
||||
foreach ($errors as $error) {
|
||||
$attrs = $error->getAttributes();
|
||||
|
||||
|
@ -20,7 +20,7 @@ final class Modifiers {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function verifyClassModifier(int $a, int $b) {
|
||||
public static function verifyClassModifier(int $a, int $b): void {
|
||||
if ($a & Modifiers::ABSTRACT && $b & Modifiers::ABSTRACT) {
|
||||
throw new Error('Multiple abstract modifiers are not allowed');
|
||||
}
|
||||
@ -41,7 +41,7 @@ final class Modifiers {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function verifyModifier(int $a, int $b) {
|
||||
public static function verifyModifier(int $a, int $b): void {
|
||||
if ($a & Modifiers::VISIBILITY_MASK && $b & Modifiers::VISIBILITY_MASK) {
|
||||
throw new Error('Multiple access type modifiers are not allowed');
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class NameContext {
|
||||
*
|
||||
* @param Name|null $namespace Null is the global namespace
|
||||
*/
|
||||
public function startNamespace(?Name $namespace = null) {
|
||||
public function startNamespace(?Name $namespace = null): void {
|
||||
$this->namespace = $namespace;
|
||||
$this->origAliases = $this->aliases = [
|
||||
Stmt\Use_::TYPE_NORMAL => [],
|
||||
@ -52,7 +52,7 @@ class NameContext {
|
||||
* @param int $type One of Stmt\Use_::TYPE_*
|
||||
* @param array $errorAttrs Attributes to use to report an error
|
||||
*/
|
||||
public function addAlias(Name $name, string $aliasName, int $type, array $errorAttrs = []) {
|
||||
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;
|
||||
@ -226,7 +226,7 @@ class NameContext {
|
||||
return $shortestName;
|
||||
}
|
||||
|
||||
private function resolveAlias(Name $name, int $type) {
|
||||
private function resolveAlias(Name $name, int $type): ?FullyQualified {
|
||||
$firstPart = $name->getFirst();
|
||||
|
||||
if ($name->isQualified()) {
|
||||
@ -249,7 +249,7 @@ class NameContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
private function getNamespaceRelativeName(string $name, string $lcName, int $type) {
|
||||
private function getNamespaceRelativeName(string $name, string $lcName, int $type): ?Name {
|
||||
if (null === $this->namespace) {
|
||||
return new Name($name);
|
||||
}
|
||||
@ -270,7 +270,7 @@ class NameContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
private function normalizeConstName(string $name) {
|
||||
private function normalizeConstName(string $name): string {
|
||||
$nsSep = strrpos($name, '\\');
|
||||
if (false === $nsSep) {
|
||||
return $name;
|
||||
|
@ -105,7 +105,7 @@ interface Node {
|
||||
*
|
||||
* @param Comment\Doc $docComment Doc comment to set
|
||||
*/
|
||||
public function setDocComment(Comment\Doc $docComment);
|
||||
public function setDocComment(Comment\Doc $docComment): void;
|
||||
|
||||
/**
|
||||
* Sets an attribute on a node.
|
||||
@ -113,7 +113,7 @@ interface Node {
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setAttribute(string $key, $value);
|
||||
public function setAttribute(string $key, $value): void;
|
||||
|
||||
/**
|
||||
* Returns whether an attribute exists.
|
||||
@ -146,5 +146,5 @@ interface Node {
|
||||
*
|
||||
* @param array $attributes
|
||||
*/
|
||||
public function setAttributes(array $attributes);
|
||||
public function setAttributes(array $attributes): void;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
|
||||
*
|
||||
* @param Comment\Doc $docComment Doc comment to set
|
||||
*/
|
||||
public function setDocComment(Comment\Doc $docComment) {
|
||||
public function setDocComment(Comment\Doc $docComment): void {
|
||||
$comments = $this->getComments();
|
||||
for ($i = count($comments) - 1; $i >= 0; $i--) {
|
||||
if ($comments[$i] instanceof Comment\Doc) {
|
||||
@ -144,7 +144,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
|
||||
$this->setAttribute('comments', $comments);
|
||||
}
|
||||
|
||||
public function setAttribute(string $key, $value) {
|
||||
public function setAttribute(string $key, $value): void {
|
||||
$this->attributes[$key] = $value;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ abstract class NodeAbstract implements Node, \JsonSerializable {
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
public function setAttributes(array $attributes) {
|
||||
public function setAttributes(array $attributes): void {
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class NodeDumper {
|
||||
}
|
||||
|
||||
/** @param Node|Comment|array $node */
|
||||
protected function dumpRecursive($node) {
|
||||
protected function dumpRecursive($node): string {
|
||||
if ($node instanceof Node) {
|
||||
$r = $node->getType();
|
||||
if ($this->dumpPositions && null !== $p = $this->dumpPosition($node)) {
|
||||
@ -108,7 +108,7 @@ class NodeDumper {
|
||||
return $r . "\n)";
|
||||
}
|
||||
|
||||
protected function dumpFlags(int $flags) {
|
||||
protected function dumpFlags(int $flags): string {
|
||||
$strs = [];
|
||||
if ($flags & Modifiers::PUBLIC) {
|
||||
$strs[] = 'PUBLIC';
|
||||
@ -135,11 +135,11 @@ class NodeDumper {
|
||||
if ($strs) {
|
||||
return implode(' | ', $strs) . ' (' . $flags . ')';
|
||||
} else {
|
||||
return $flags;
|
||||
return (string) $flags;
|
||||
}
|
||||
}
|
||||
|
||||
protected function dumpIncludeType(int $type) {
|
||||
protected function dumpIncludeType(int $type): string {
|
||||
$map = [
|
||||
Include_::TYPE_INCLUDE => 'TYPE_INCLUDE',
|
||||
Include_::TYPE_INCLUDE_ONCE => 'TYPE_INCLUDE_ONCE',
|
||||
@ -148,12 +148,12 @@ class NodeDumper {
|
||||
];
|
||||
|
||||
if (!isset($map[$type])) {
|
||||
return $type;
|
||||
return (string) $type;
|
||||
}
|
||||
return $map[$type] . ' (' . $type . ')';
|
||||
}
|
||||
|
||||
protected function dumpUseType(int $type) {
|
||||
protected function dumpUseType(int $type): string {
|
||||
$map = [
|
||||
Use_::TYPE_UNKNOWN => 'TYPE_UNKNOWN',
|
||||
Use_::TYPE_NORMAL => 'TYPE_NORMAL',
|
||||
@ -162,7 +162,7 @@ class NodeDumper {
|
||||
];
|
||||
|
||||
if (!isset($map[$type])) {
|
||||
return $type;
|
||||
return (string) $type;
|
||||
}
|
||||
return $map[$type] . ' (' . $type . ')';
|
||||
}
|
||||
@ -191,7 +191,7 @@ class NodeDumper {
|
||||
}
|
||||
|
||||
// Copied from Error class
|
||||
private function toColumn(string $code, int $pos) {
|
||||
private function toColumn(string $code, int $pos): int {
|
||||
if ($pos > strlen($code)) {
|
||||
throw new \RuntimeException('Invalid position information');
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||
*
|
||||
* @param NodeVisitor $visitor Visitor to add
|
||||
*/
|
||||
public function addVisitor(NodeVisitor $visitor) {
|
||||
public function addVisitor(NodeVisitor $visitor): void {
|
||||
$this->visitors[] = $visitor;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||
*
|
||||
* @param NodeVisitor $visitor
|
||||
*/
|
||||
public function removeVisitor(NodeVisitor $visitor) {
|
||||
public function removeVisitor(NodeVisitor $visitor): void {
|
||||
foreach ($this->visitors as $index => $storedVisitor) {
|
||||
if ($storedVisitor === $visitor) {
|
||||
unset($this->visitors[$index]);
|
||||
@ -272,7 +272,7 @@ class NodeTraverser implements NodeTraverserInterface {
|
||||
return $nodes;
|
||||
}
|
||||
|
||||
private function ensureReplacementReasonable(Node $old, Node $new) {
|
||||
private function ensureReplacementReasonable(Node $old, Node $new): void {
|
||||
if ($old instanceof Node\Stmt && $new instanceof Node\Expr) {
|
||||
throw new \LogicException(
|
||||
"Trying to replace statement ({$old->getType()}) " .
|
||||
|
@ -8,14 +8,14 @@ interface NodeTraverserInterface {
|
||||
*
|
||||
* @param NodeVisitor $visitor Visitor to add
|
||||
*/
|
||||
public function addVisitor(NodeVisitor $visitor);
|
||||
public function addVisitor(NodeVisitor $visitor): void;
|
||||
|
||||
/**
|
||||
* Removes an added visitor.
|
||||
*
|
||||
* @param NodeVisitor $visitor
|
||||
*/
|
||||
public function removeVisitor(NodeVisitor $visitor);
|
||||
public function removeVisitor(NodeVisitor $visitor): void;
|
||||
|
||||
/**
|
||||
* Traverses an array of nodes using the registered visitors.
|
||||
|
@ -160,7 +160,7 @@ class NameResolver extends NodeVisitorAbstract {
|
||||
return null;
|
||||
}
|
||||
|
||||
private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null) {
|
||||
private function addAlias(Node\UseItem $use, int $type, ?Name $prefix = null): void {
|
||||
// Add prefix for group uses
|
||||
$name = $prefix ? Name::concat($prefix, $use->name) : $use->name;
|
||||
// Type is determined either by individual element or whole use declaration
|
||||
@ -172,7 +172,7 @@ class NameResolver extends NodeVisitorAbstract {
|
||||
}
|
||||
|
||||
/** @param Stmt\Function_|Stmt\ClassMethod|Expr\Closure $node */
|
||||
private function resolveSignature($node) {
|
||||
private function resolveSignature($node): void {
|
||||
foreach ($node->params as $param) {
|
||||
$param->type = $this->resolveType($param->type);
|
||||
$this->resolveAttrGroups($param);
|
||||
@ -180,6 +180,10 @@ class NameResolver extends NodeVisitorAbstract {
|
||||
$node->returnType = $this->resolveType($node->returnType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Node\Identifier|Name|Node\ComplexType|null $node
|
||||
* @return Node\Identifier|Name|Node\ComplexType|null
|
||||
*/
|
||||
private function resolveType(?Node $node) {
|
||||
if ($node instanceof Name) {
|
||||
return $this->resolveClassName($node);
|
||||
@ -236,16 +240,16 @@ class NameResolver extends NodeVisitorAbstract {
|
||||
return $name;
|
||||
}
|
||||
|
||||
protected function resolveClassName(Name $name) {
|
||||
protected function resolveClassName(Name $name): Name {
|
||||
return $this->resolveName($name, Stmt\Use_::TYPE_NORMAL);
|
||||
}
|
||||
|
||||
protected function addNamespacedName(Node $node) {
|
||||
protected function addNamespacedName(Node $node): void {
|
||||
$node->namespacedName = Name::concat(
|
||||
$this->nameContext->getNamespace(), (string) $node->name);
|
||||
}
|
||||
|
||||
protected function resolveAttrGroups(Node $node) {
|
||||
protected function resolveAttrGroups(Node $node): void {
|
||||
foreach ($node->attrGroups as $attrGroup) {
|
||||
foreach ($attrGroup->attrs as $attr) {
|
||||
$attr->name = $this->resolveClassName($attr->name);
|
||||
|
@ -1146,7 +1146,7 @@ class Php7 extends \PhpParser\ParserAbstract
|
||||
3, 3, 6, 3, 1, 1, 2, 1
|
||||
);
|
||||
|
||||
protected function initReduceCallbacks() {
|
||||
protected function initReduceCallbacks(): void {
|
||||
$this->reduceCallbacks = [
|
||||
0 => function ($stackPos) {
|
||||
$this->semValue = $this->semStack[$stackPos];
|
||||
|
@ -1164,7 +1164,7 @@ class Php8 extends \PhpParser\ParserAbstract
|
||||
3, 3, 6, 3, 1, 1, 2, 1
|
||||
);
|
||||
|
||||
protected function initReduceCallbacks() {
|
||||
protected function initReduceCallbacks(): void {
|
||||
$this->reduceCallbacks = [
|
||||
0 => function ($stackPos) {
|
||||
$this->semValue = $this->semStack[$stackPos];
|
||||
|
@ -131,7 +131,7 @@ abstract class ParserAbstract implements Parser {
|
||||
/**
|
||||
* Initialize $reduceCallbacks map.
|
||||
*/
|
||||
abstract protected function initReduceCallbacks();
|
||||
abstract protected function initReduceCallbacks(): void;
|
||||
|
||||
/**
|
||||
* Creates a parser instance.
|
||||
@ -201,7 +201,7 @@ abstract class ParserAbstract implements Parser {
|
||||
return $this->lexer;
|
||||
}
|
||||
|
||||
protected function doParse() {
|
||||
protected function doParse(): ?array {
|
||||
// We start off with no lookahead-token
|
||||
$symbol = self::SYMBOL_NONE;
|
||||
|
||||
@ -404,7 +404,7 @@ abstract class ParserAbstract implements Parser {
|
||||
throw new \RuntimeException('Reached end of parser loop');
|
||||
}
|
||||
|
||||
protected function emitError(Error $error) {
|
||||
protected function emitError(Error $error): void {
|
||||
$this->errorHandler->handleError($error);
|
||||
}
|
||||
|
||||
@ -465,32 +465,32 @@ abstract class ParserAbstract implements Parser {
|
||||
*/
|
||||
|
||||
/*
|
||||
protected function traceNewState($state, $symbol) {
|
||||
protected function traceNewState($state, $symbol): void {
|
||||
echo '% State ' . $state
|
||||
. ', Lookahead ' . ($symbol == self::SYMBOL_NONE ? '--none--' : $this->symbolToName[$symbol]) . "\n";
|
||||
}
|
||||
|
||||
protected function traceRead($symbol) {
|
||||
protected function traceRead($symbol): void {
|
||||
echo '% Reading ' . $this->symbolToName[$symbol] . "\n";
|
||||
}
|
||||
|
||||
protected function traceShift($symbol) {
|
||||
protected function traceShift($symbol): void {
|
||||
echo '% Shift ' . $this->symbolToName[$symbol] . "\n";
|
||||
}
|
||||
|
||||
protected function traceAccept() {
|
||||
protected function traceAccept(): void {
|
||||
echo "% Accepted.\n";
|
||||
}
|
||||
|
||||
protected function traceReduce($n) {
|
||||
protected function traceReduce($n): void {
|
||||
echo '% Reduce by (' . $n . ') ' . $this->productions[$n] . "\n";
|
||||
}
|
||||
|
||||
protected function tracePop($state) {
|
||||
protected function tracePop($state): void {
|
||||
echo '% Recovering, uncovered state ' . $state . "\n";
|
||||
}
|
||||
|
||||
protected function traceDiscard($symbol) {
|
||||
protected function traceDiscard($symbol): void {
|
||||
echo '% Discard ' . $this->symbolToName[$symbol] . "\n";
|
||||
}
|
||||
*/
|
||||
@ -561,7 +561,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt) {
|
||||
private function fixupNamespaceAttributes(Node\Stmt\Namespace_ $stmt): void {
|
||||
// We moved the statements into the namespace node, as such the end of the namespace node
|
||||
// needs to be extended to the end of the statements.
|
||||
if (empty($stmt->stmts)) {
|
||||
@ -629,6 +629,7 @@ abstract class ParserAbstract implements Parser {
|
||||
return $style;
|
||||
}
|
||||
|
||||
/** @return Name|Identifier */
|
||||
protected function handleBuiltinTypes(Name $name) {
|
||||
if (!$name->isUnqualified()) {
|
||||
return $name;
|
||||
@ -666,7 +667,7 @@ abstract class ParserAbstract implements Parser {
|
||||
return Double::KIND_DOUBLE;
|
||||
}
|
||||
|
||||
protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false) {
|
||||
protected function parseLNumber(string $str, array $attributes, bool $allowInvalidOctal = false): Int_ {
|
||||
try {
|
||||
return Int_::fromString($str, $attributes, $allowInvalidOctal);
|
||||
} catch (Error $error) {
|
||||
@ -700,7 +701,7 @@ abstract class ParserAbstract implements Parser {
|
||||
protected function stripIndentation(
|
||||
string $string, int $indentLen, string $indentChar,
|
||||
bool $newlineAtStart, bool $newlineAtEnd, array $attributes
|
||||
) {
|
||||
): string {
|
||||
if ($indentLen === 0) {
|
||||
return $string;
|
||||
}
|
||||
@ -733,7 +734,7 @@ abstract class ParserAbstract implements Parser {
|
||||
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;
|
||||
|
||||
@ -895,7 +896,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClassModifier(int $a, int $b, int $modifierPos) {
|
||||
protected function checkClassModifier(int $a, int $b, int $modifierPos): void {
|
||||
try {
|
||||
Modifiers::verifyClassModifier($a, $b);
|
||||
} catch (Error $error) {
|
||||
@ -904,7 +905,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkModifier(int $a, int $b, int $modifierPos) {
|
||||
protected function checkModifier(int $a, int $b, int $modifierPos): void {
|
||||
// Jumping through some hoops here because verifyModifier() is also used elsewhere
|
||||
try {
|
||||
Modifiers::verifyModifier($a, $b);
|
||||
@ -914,7 +915,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkParam(Param $node) {
|
||||
protected function checkParam(Param $node): void {
|
||||
if ($node->variadic && null !== $node->default) {
|
||||
$this->emitError(new Error(
|
||||
'Variadic parameter cannot have a default value',
|
||||
@ -923,7 +924,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkTryCatch(TryCatch $node) {
|
||||
protected function checkTryCatch(TryCatch $node): void {
|
||||
if (empty($node->catches) && null === $node->finally) {
|
||||
$this->emitError(new Error(
|
||||
'Cannot use try without catch or finally', $node->getAttributes()
|
||||
@ -931,7 +932,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkNamespace(Namespace_ $node) {
|
||||
protected function checkNamespace(Namespace_ $node): void {
|
||||
if (null !== $node->stmts) {
|
||||
foreach ($node->stmts as $stmt) {
|
||||
if ($stmt instanceof Namespace_) {
|
||||
@ -943,7 +944,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private function checkClassName(?Identifier $name, int $namePos) {
|
||||
private function checkClassName(?Identifier $name, int $namePos): void {
|
||||
if (null !== $name && $name->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf('Cannot use \'%s\' as class name as it is reserved', $name),
|
||||
@ -952,7 +953,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
private function checkImplementedInterfaces(array $interfaces) {
|
||||
private function checkImplementedInterfaces(array $interfaces): void {
|
||||
foreach ($interfaces as $interface) {
|
||||
if ($interface->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
@ -963,7 +964,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClass(Class_ $node, int $namePos) {
|
||||
protected function checkClass(Class_ $node, int $namePos): void {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
|
||||
if ($node->extends && $node->extends->isSpecialClassName()) {
|
||||
@ -976,17 +977,17 @@ abstract class ParserAbstract implements Parser {
|
||||
$this->checkImplementedInterfaces($node->implements);
|
||||
}
|
||||
|
||||
protected function checkInterface(Interface_ $node, int $namePos) {
|
||||
protected function checkInterface(Interface_ $node, int $namePos): void {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
$this->checkImplementedInterfaces($node->extends);
|
||||
}
|
||||
|
||||
protected function checkEnum(Enum_ $node, int $namePos) {
|
||||
protected function checkEnum(Enum_ $node, int $namePos): void {
|
||||
$this->checkClassName($node->name, $namePos);
|
||||
$this->checkImplementedInterfaces($node->implements);
|
||||
}
|
||||
|
||||
protected function checkClassMethod(ClassMethod $node, int $modifierPos) {
|
||||
protected function checkClassMethod(ClassMethod $node, int $modifierPos): void {
|
||||
if ($node->flags & Modifiers::STATIC) {
|
||||
switch ($node->name->toLowerString()) {
|
||||
case '__construct':
|
||||
@ -1014,7 +1015,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkClassConst(ClassConst $node, int $modifierPos) {
|
||||
protected function checkClassConst(ClassConst $node, int $modifierPos): void {
|
||||
if ($node->flags & Modifiers::STATIC) {
|
||||
$this->emitError(new Error(
|
||||
"Cannot use 'static' as constant modifier",
|
||||
@ -1032,7 +1033,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkProperty(Property $node, int $modifierPos) {
|
||||
protected function checkProperty(Property $node, int $modifierPos): void {
|
||||
if ($node->flags & Modifiers::ABSTRACT) {
|
||||
$this->emitError(new Error('Properties cannot be declared abstract',
|
||||
$this->getAttributesAt($modifierPos)));
|
||||
@ -1044,7 +1045,7 @@ abstract class ParserAbstract implements Parser {
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkUseUse(UseItem $node, int $namePos) {
|
||||
protected function checkUseUse(UseItem $node, int $namePos): void {
|
||||
if ($node->alias && $node->alias->isSpecialClassName()) {
|
||||
$this->emitError(new Error(
|
||||
sprintf(
|
||||
|
@ -165,7 +165,7 @@ abstract class PrettyPrinterAbstract {
|
||||
/**
|
||||
* Reset pretty printing state.
|
||||
*/
|
||||
protected function resetState() {
|
||||
protected function resetState(): void {
|
||||
$this->indentLevel = 0;
|
||||
$this->nl = "\n";
|
||||
$this->origTokens = null;
|
||||
@ -176,7 +176,7 @@ abstract class PrettyPrinterAbstract {
|
||||
*
|
||||
* @param int $level Level in number of spaces
|
||||
*/
|
||||
protected function setIndentLevel(int $level) {
|
||||
protected function setIndentLevel(int $level): void {
|
||||
$this->indentLevel = $level;
|
||||
$this->nl = "\n" . \str_repeat(' ', $level);
|
||||
}
|
||||
@ -184,7 +184,7 @@ abstract class PrettyPrinterAbstract {
|
||||
/**
|
||||
* Increase indentation level.
|
||||
*/
|
||||
protected function indent() {
|
||||
protected function indent(): void {
|
||||
$this->indentLevel += 4;
|
||||
$this->nl .= ' ';
|
||||
}
|
||||
@ -192,7 +192,7 @@ abstract class PrettyPrinterAbstract {
|
||||
/**
|
||||
* Decrease indentation level.
|
||||
*/
|
||||
protected function outdent() {
|
||||
protected function outdent(): void {
|
||||
assert($this->indentLevel >= 4);
|
||||
$this->indentLevel -= 4;
|
||||
$this->nl = "\n" . str_repeat(' ', $this->indentLevel);
|
||||
@ -253,7 +253,7 @@ abstract class PrettyPrinterAbstract {
|
||||
*
|
||||
* @param Node[] $nodes Array of nodes
|
||||
*/
|
||||
protected function preprocessNodes(array $nodes) {
|
||||
protected function preprocessNodes(array $nodes): void {
|
||||
/* We can use semicolon-namespaces unless there is a global namespace declaration */
|
||||
$this->canUseSemicolonNamespaces = true;
|
||||
foreach ($nodes as $node) {
|
||||
@ -500,7 +500,7 @@ abstract class PrettyPrinterAbstract {
|
||||
return ltrim($this->handleMagicTokens($result));
|
||||
}
|
||||
|
||||
protected function pFallback(Node $node) {
|
||||
protected function pFallback(Node $node): string {
|
||||
return $this->{'p' . $node->getType()}($node);
|
||||
}
|
||||
|
||||
@ -1011,7 +1011,7 @@ abstract class PrettyPrinterAbstract {
|
||||
* @param string $str
|
||||
* @param string $append
|
||||
*/
|
||||
protected function safeAppend(string &$str, string $append) {
|
||||
protected function safeAppend(string &$str, string $append): void {
|
||||
if ($str === "") {
|
||||
$str = $append;
|
||||
return;
|
||||
@ -1127,7 +1127,7 @@ abstract class PrettyPrinterAbstract {
|
||||
*
|
||||
* The label char map determines whether a certain character may occur in a label.
|
||||
*/
|
||||
protected function initializeLabelCharMap() {
|
||||
protected function initializeLabelCharMap(): void {
|
||||
if ($this->labelCharMap) {
|
||||
return;
|
||||
}
|
||||
@ -1146,7 +1146,7 @@ abstract class PrettyPrinterAbstract {
|
||||
*
|
||||
* The node list differ is used to determine differences between two array subnodes.
|
||||
*/
|
||||
protected function initializeNodeListDiffer() {
|
||||
protected function initializeNodeListDiffer(): void {
|
||||
if ($this->nodeListDiffer) {
|
||||
return;
|
||||
}
|
||||
@ -1166,7 +1166,7 @@ abstract class PrettyPrinterAbstract {
|
||||
* The fixup map is used to determine whether a certain subnode of a certain node may require
|
||||
* some kind of "fixup" operation, e.g. the addition of parenthesis or braces.
|
||||
*/
|
||||
protected function initializeFixupMap() {
|
||||
protected function initializeFixupMap(): void {
|
||||
if ($this->fixupMap) {
|
||||
return;
|
||||
}
|
||||
@ -1250,7 +1250,7 @@ abstract class PrettyPrinterAbstract {
|
||||
* The removal map is used to determine which additional tokens should be removed when a
|
||||
* certain node is replaced by null.
|
||||
*/
|
||||
protected function initializeRemovalMap() {
|
||||
protected function initializeRemovalMap(): void {
|
||||
if ($this->removalMap) {
|
||||
return;
|
||||
}
|
||||
@ -1297,7 +1297,7 @@ abstract class PrettyPrinterAbstract {
|
||||
];
|
||||
}
|
||||
|
||||
protected function initializeInsertionMap() {
|
||||
protected function initializeInsertionMap(): void {
|
||||
if ($this->insertionMap) {
|
||||
return;
|
||||
}
|
||||
@ -1341,7 +1341,7 @@ abstract class PrettyPrinterAbstract {
|
||||
];
|
||||
}
|
||||
|
||||
protected function initializeListInsertionMap() {
|
||||
protected function initializeListInsertionMap(): void {
|
||||
if ($this->listInsertionMap) {
|
||||
return;
|
||||
}
|
||||
@ -1439,7 +1439,7 @@ abstract class PrettyPrinterAbstract {
|
||||
];
|
||||
}
|
||||
|
||||
protected function initializeEmptyListInsertionMap() {
|
||||
protected function initializeEmptyListInsertionMap(): void {
|
||||
if ($this->emptyListInsertionMap) {
|
||||
return;
|
||||
}
|
||||
@ -1504,7 +1504,7 @@ abstract class PrettyPrinterAbstract {
|
||||
];
|
||||
}
|
||||
|
||||
protected function initializeModifierChangeMap() {
|
||||
protected function initializeModifierChangeMap(): void {
|
||||
if ($this->modifierChangeMap) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user