Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CliHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function highlightToken(int $type, string $value): string
return $prefix . $value . "\x1b[0m";
}

/** @param Token::TOKEN_TYPE_* $type */
private function prefix(int $type): string|null
{
if (! isset(self::TOKEN_TYPE_TO_HIGHLIGHT[$type])) {
Expand Down
2 changes: 2 additions & 0 deletions src/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
) {
}

/** @param Token::TOKEN_TYPE_* $exceptTokenType */
public function next(int|null $exceptTokenType = null): Token|null
{
while ($token = $this->tokens[++$this->position] ?? null) {
Expand All @@ -27,6 +28,7 @@ public function next(int|null $exceptTokenType = null): Token|null
return null;
}

/** @param Token::TOKEN_TYPE_* $exceptTokenType */
public function previous(int|null $exceptTokenType = null): Token|null
{
while ($token = $this->tokens[--$this->position] ?? null) {
Expand Down
2 changes: 2 additions & 0 deletions src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface Highlighter

/**
* Highlights a token depending on its type.
*
* @param Token::TOKEN_TYPE_* $type
*/
public function highlightToken(int $type, string $value): string;

Expand Down
1 change: 1 addition & 0 deletions src/HtmlHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function highlightToken(int $type, string $value): string
return '<span ' . $attributes . '>' . $value . '</span>';
}

/** @param Token::TOKEN_TYPE_* $type */
public function attributes(int $type): string|null
{
if (! isset(self::TOKEN_TYPE_TO_HIGHLIGHT[$type])) {
Expand Down
12 changes: 6 additions & 6 deletions src/SqlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function format(string $string, string $indentString = ' '): string
for ($j = 1; $j <= 250; $j++) {
// Reached end of string
$next = $subCursor->next(Token::TOKEN_TYPE_WHITESPACE);
if (! $next) {
if ($next === null) {
break;
}

Expand Down Expand Up @@ -215,7 +215,7 @@ public function format(string $string, string $indentString = ' '): string

// Take out the preceding space unless there was whitespace there in the original query
$prevToken = $cursor->subCursor()->previous();
if ($prevToken && ! $prevToken->isOfType(Token::TOKEN_TYPE_WHITESPACE)) {
if ($prevToken !== null && ! $prevToken->isOfType(Token::TOKEN_TYPE_WHITESPACE)) {
$return = rtrim($return, ' ');
}

Expand Down Expand Up @@ -328,9 +328,9 @@ public function format(string $string, string $indentString = ' '): string
} elseif ($token->isOfType(Token::TOKEN_TYPE_BOUNDARY)) {
// Multiple boundary characters in a row should not have spaces between them (not including parentheses)
$prevNotWhitespaceToken = $cursor->subCursor()->previous(Token::TOKEN_TYPE_WHITESPACE);
if ($prevNotWhitespaceToken && $prevNotWhitespaceToken->isOfType(Token::TOKEN_TYPE_BOUNDARY)) {
if ($prevNotWhitespaceToken !== null && $prevNotWhitespaceToken->isOfType(Token::TOKEN_TYPE_BOUNDARY)) {
$prevToken = $cursor->subCursor()->previous();
if ($prevToken && ! $prevToken->isOfType(Token::TOKEN_TYPE_WHITESPACE)) {
if ($prevToken !== null && ! $prevToken->isOfType(Token::TOKEN_TYPE_WHITESPACE)) {
$return = rtrim($return, ' ');
}
}
Expand Down Expand Up @@ -358,12 +358,12 @@ public function format(string $string, string $indentString = ' '): string
}

$nextNotWhitespace = $cursor->subCursor()->next(Token::TOKEN_TYPE_WHITESPACE);
if (! $nextNotWhitespace || ! $nextNotWhitespace->isOfType(Token::TOKEN_TYPE_NUMBER)) {
if ($nextNotWhitespace === null || ! $nextNotWhitespace->isOfType(Token::TOKEN_TYPE_NUMBER)) {
continue;
}

$prev = $cursor->subCursor()->previous(Token::TOKEN_TYPE_WHITESPACE);
if (! $prev) {
if ($prev === null) {
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function type(): int
return $this->type;
}

/** @param self::TOKEN_TYPE_* ...$types */
public function isOfType(int ...$types): bool
{
return in_array($this->type, $types, true);
Expand Down