Skip to content

Commit

Permalink
Code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tuqqu committed Aug 29, 2022
1 parent 8d47a30 commit eaf80fd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 84 deletions.
12 changes: 6 additions & 6 deletions src/Ast/IdentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public function __construct(
public static function fromExprList(ExprList $list): self
{
return new self(\array_map(
static fn (Expr $expr): Ident => $expr instanceof Ident ?
$expr :
throw new InvalidArgument('Cannot create IdentList from an arbitrary expression list'),
static fn (Expr $expr): Ident => $expr instanceof Ident
? $expr
: throw new InvalidArgument('Cannot create IdentList from an arbitrary expression list'),
$list->exprs,
));
}

public static function fromTypeList(TypeList $list): self
{
return new self(\array_map(
static fn (Type $type): Ident => $type instanceof SingleTypeName ?
$type->name :
throw new InvalidArgument('Cannot create IdentList from an arbitrary type list'),
static fn (Type $type): Ident => $type instanceof SingleTypeName
? $type->name
: throw new InvalidArgument('Cannot create IdentList from an arbitrary type list'),
$list->types,
));
}
Expand Down
12 changes: 6 additions & 6 deletions src/NodeDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ private static function type(AstNode $node): string
default => null,
};

return $type === null ?
self::name($node) :
\sprintf("[%s] %s", $type, self::name($node));
return $type === null
? self::name($node)
: \sprintf("[%s] %s", $type, self::name($node));
}

private function printProp(AstNode $node, \ReflectionProperty $property, int $indent): void
Expand Down Expand Up @@ -149,9 +149,9 @@ private function getPos(AstNode $node): string
$pos = new Position(
$value->offset,
$value->line,
$this->showFilename ?
$value->filename :
null
$this->showFilename
? $value->filename
: null
);

return (string) $pos;
Expand Down
144 changes: 72 additions & 72 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,27 +348,27 @@ private function parseFuncOrMethodDecl(): FuncDecl|MethodDecl
{
$keyword = $this->parseKeyword(Token::Func);

$receiver = $this->match(Token::LeftParen) ?
$this->parseParams(false) :
null;
$receiver = $this->match(Token::LeftParen)
? $this->parseParams(false)
: null;

$name = $this->parseIdent();

$typeParams = $receiver === null && $this->match(Token::LeftBracket) ?
$this->parseTypeParams() :
null;
$typeParams = $receiver === null && $this->match(Token::LeftBracket)
? $this->parseTypeParams()
: null;

$sign = $this->parseSignature();

$body = $this->match(Token::LeftBrace) ?
$this->parseBlockStmt() :
null;
$body = $this->match(Token::LeftBrace)
? $this->parseBlockStmt()
: null;

$this->parseSemicolon();

return $receiver === null ?
new FuncDecl($keyword, $name, $typeParams, $sign, $body) :
new MethodDecl($keyword, $receiver, $name, $sign, $body);
return $receiver === null
? new FuncDecl($keyword, $name, $typeParams, $sign, $body)
: new MethodDecl($keyword, $receiver, $name, $sign, $body);
}

private function parseStmt(): Stmt
Expand Down Expand Up @@ -487,9 +487,9 @@ private function parseTypeTerm(): TypeTerm
$tilda = $this->tryParseOperator(Token::Tilda);
$type = $this->parseType();

return $tilda !== null ?
new UnderlyingType($tilda, $type) :
$type;
return $tilda !== null
? new UnderlyingType($tilda, $type)
: $type;
}

private function parseSelectStmt(): SelectStmt
Expand Down Expand Up @@ -651,9 +651,9 @@ private function parseForStmt(): ForStmt
case $this->checkAheadTill(Token::LeftBrace, Token::Semicolon):
$init = $this->parseSimpleStmt();
$cond = $this->parseSimpleStmt();
$post = $this->match(Token::LeftBrace) ?
null :
$this->parseSimpleStmt(true);
$post = $this->match(Token::LeftBrace)
? null
: $this->parseSimpleStmt(true);

$iteration = new ForClause($init, $cond, $post);
break;
Expand Down Expand Up @@ -839,9 +839,9 @@ private function doParseCallExpr(): CallExpr
private function parseEmptyStmt(bool $skipSemi = false): EmptyStmt
{
return new EmptyStmt(
$skipSemi ?
$this->peek()->pos :
$this->consume(Token::Semicolon)->pos
$skipSemi
? $this->peek()->pos
: $this->consume(Token::Semicolon)->pos
);
}

Expand All @@ -850,9 +850,9 @@ private function parseSwitchStmt(): SwitchStmt
$keyword = $this->parseKeyword(Token::Switch);
$this->inCfHeader();

$init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) ?
$this->parseSimpleStmt() :
null;
$init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon)
? $this->parseSimpleStmt()
: null;

// ExprSwitchStmt
// switch {}
Expand Down Expand Up @@ -921,9 +921,9 @@ private function parseIfStmt(): IfStmt
$if = $this->parseKeyword(Token::If);
$this->inCfHeader();

$init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon) ?
$this->parseSimpleStmt() :
null;
$init = $this->checkAheadTill(Token::LeftBrace, Token::Semicolon)
? $this->parseSimpleStmt()
: null;

$cond = $this->parseExpr();
$this->outCfHeader();
Expand Down Expand Up @@ -985,9 +985,9 @@ private function parseDeferStmt(): DeferStmt
private function parseReturnStmt(): ReturnStmt
{
$keyword = $this->parseKeyword(Token::Return);
$exprs = $this->match(Token::Semicolon) ?
null :
$this->parseExprList();
$exprs = $this->match(Token::Semicolon)
? null
: $this->parseExprList();

$this->parseSemicolon();

Expand Down Expand Up @@ -1239,9 +1239,9 @@ private function parseCompositeLit(?Expr $type = null): CompositeLit
}

$lBrace = $this->parsePunctuation(Token::LeftBrace);
$elemList = $this->match(Token::RightBrace) ?
null :
$this->parseElementList();
$elemList = $this->match(Token::RightBrace)
? null
: $this->parseElementList();
$rBrace = $this->parsePunctuation(Token::RightBrace);

return new CompositeLit($type, $lBrace, $elemList, $rBrace);
Expand All @@ -1252,9 +1252,9 @@ private static function tryTypeFromExpr(?Expr $expr): ?Type
return match (true) {
$expr instanceof Type => $expr,
$expr instanceof Ident => new SingleTypeName($expr, null),
$expr instanceof SelectorExpr => $expr->expr instanceof Ident ?
new QualifiedTypeName($expr->expr, new SingleTypeName($expr->selector, null)) :
null,
$expr instanceof SelectorExpr => $expr->expr instanceof Ident
? new QualifiedTypeName($expr->expr, new SingleTypeName($expr->selector, null))
: null,
default => null,
};
}
Expand Down Expand Up @@ -1295,9 +1295,9 @@ private function parseKeyedElement(): KeyedElement

private function parseElement(): Expr
{
return $this->match(Token::LeftBrace) ?
$this->parseCompositeLit() :
$this->parseExpr();
return $this->match(Token::LeftBrace)
? $this->parseCompositeLit()
: $this->parseExpr();
}

private function parseCallExpr(Expr $expr): CallExpr
Expand Down Expand Up @@ -1531,9 +1531,9 @@ private function parseParamDecls(bool $variadic): array

private function parseResult(): Params|Type|null
{
return $this->match(Token::LeftParen) ?
$this->parseParams(false) :
$this->tryParseType();
return $this->match(Token::LeftParen)
? $this->parseParams(false)
: $this->tryParseType();
}

private function tryParseType(): ?Type
Expand Down Expand Up @@ -1765,9 +1765,9 @@ private function parseArrayOrSliceType(): ArrayType|SliceType
$rParen = $this->parsePunctuation(Token::RightBracket);
$elemType = $this->parseType();

return $size === null ?
new SliceType($lParen, $rParen, $elemType) :
new ArrayType($lParen, $size, $rParen, $elemType);
return $size === null
? new SliceType($lParen, $rParen, $elemType)
: new ArrayType($lParen, $size, $rParen, $elemType);
}

private function parseAnyOperator(): Operator
Expand All @@ -1782,9 +1782,9 @@ private function parseOperator(Token $token): Operator

private function tryParseOperator(Token $token): ?Operator
{
return $this->match($token) ?
Operator::fromLexeme($this->consume($token)) :
null;
return $this->match($token)
? Operator::fromLexeme($this->consume($token))
: null;
}

private function parseIdent(): Ident
Expand All @@ -1794,30 +1794,30 @@ private function parseIdent(): Ident

private function tryParseIdent(): ?Ident
{
return $this->match(Token::Ident) ?
Ident::fromLexeme($this->consume(Token::Ident)) :
null;
return $this->match(Token::Ident)
? Ident::fromLexeme($this->consume(Token::Ident))
: null;
}

private function parseTypeName(): TypeName
{
$ident = Ident::fromLexeme($this->consume(Token::Ident));

$typeName = $this->consumeIf(Token::Dot) !== null ?
Ident::fromLexeme($this->consume(Token::Ident)) :
null;
$typeName = $this->consumeIf(Token::Dot) !== null
? Ident::fromLexeme($this->consume(Token::Ident))
: null;

$typeArgs = $this->match(Token::LeftBracket) ?
$this->parseTypeArgs() :
null;
$typeArgs = $this->match(Token::LeftBracket)
? $this->parseTypeArgs()
: null;

if ($typeArgs !== null && empty($typeArgs)) {
$this->error('empty type parameter list');
}

return $typeName === null ?
new SingleTypeName($ident, $typeArgs) :
new QualifiedTypeName(
return $typeName === null
? new SingleTypeName($ident, $typeArgs)
: new QualifiedTypeName(
$ident,
new SingleTypeName($typeName, $typeArgs),
);
Expand All @@ -1827,9 +1827,9 @@ private function parseTypeNameInParams(): TypeName
{
$ident = Ident::fromLexeme($this->consume(Token::Ident));

$typeName = $this->consumeIf(Token::Dot) !== null ?
Ident::fromLexeme($this->consume(Token::Ident)) :
null;
$typeName = $this->consumeIf(Token::Dot) !== null
? Ident::fromLexeme($this->consume(Token::Ident))
: null;

$typeArgs = null;

Expand All @@ -1840,9 +1840,9 @@ private function parseTypeNameInParams(): TypeName
$typeArgs = $this->parseTypeArgs();
}

return $typeName === null ?
new SingleTypeName($ident, $typeArgs) :
new QualifiedTypeName(
return $typeName === null
? new SingleTypeName($ident, $typeArgs)
: new QualifiedTypeName(
$ident,
new SingleTypeName($typeName, $typeArgs),
);
Expand Down Expand Up @@ -1913,9 +1913,9 @@ private function parsePunctuation(Token $token): Punctuation

private function tryParsePunctuation(Token $token): ?Punctuation
{
return $this->match($token) ?
Punctuation::fromLexeme($this->consume($token)) :
null;
return $this->match($token)
? Punctuation::fromLexeme($this->consume($token))
: null;
}

private function inCfHeader(): void
Expand All @@ -1937,9 +1937,9 @@ private function parseSemicolon(): void

private function consume(Token $token): Lexeme
{
return $this->match($token) ?
$this->advance() :
$this->error(\sprintf(
return $this->match($token)
? $this->advance()
: $this->error(\sprintf(
'unexpected token \'%s\', expecting \'%s\'',
$this->peek()->token->name,
$token->name,
Expand Down

0 comments on commit eaf80fd

Please sign in to comment.