Skip to content

Commit

Permalink
Fix more long throw lines
Browse files Browse the repository at this point in the history
  • Loading branch information
uuf6429 committed Dec 21, 2024
1 parent 67e03a1 commit 287c946
Showing 1 changed file with 66 additions and 12 deletions.
78 changes: 66 additions & 12 deletions src/Behat/Gherkin/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public function parse($input, $file = null)
try {
$this->lexer->analyse($this->input, 'en');
} catch (LexerException $e) {
throw new ParserException(sprintf('Lexer exception "%s" thrown for file %s', $e->getMessage(), $file), 0, $e);
throw new ParserException(
sprintf('Lexer exception "%s" thrown for file %s', $e->getMessage(), $file),
0,
$e
);
}

$feature = null;
Expand All @@ -89,15 +93,27 @@ public function parse($input, $file = null)
}

if ($feature && $node instanceof FeatureNode) {
throw new ParserException(sprintf('Only one feature is allowed per feature file. But %s got multiple.', $this->file));
throw new ParserException(sprintf(
'Only one feature is allowed per feature file. But %s got multiple.',
$this->file
));
}

if (is_string($node)) {
throw new ParserException(sprintf('Expected Feature, but got text: "%s"%s', $node, $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Feature, but got text: "%s"%s',
$node,
$this->file ? ' in file: ' . $this->file : ''
));
}

if (!$node instanceof FeatureNode) {
throw new ParserException(sprintf('Expected Feature, but got %s on line: %d%s', $node->getKeyword(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Feature, but got %s on line: %d%s',
$node->getKeyword(),
$node->getLine(),
$this->file ? ' in file: ' . $this->file : ''
));
}
}

Expand All @@ -122,7 +138,13 @@ protected function expectTokenType($type)

$token = $this->lexer->predictToken();

throw new ParserException(sprintf('Expected %s token, but got %s on line: %d%s', implode(' or ', $types), $this->predictTokenType(), $token['line'], $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected %s token, but got %s on line: %d%s',
implode(' or ', $types),
$this->predictTokenType(),
$token['line'],
$this->file ? ' in file: ' . $this->file : ''
));
}

/**
Expand Down Expand Up @@ -308,11 +330,20 @@ protected function parseBackground()
}

if (is_string($node)) {
throw new ParserException(sprintf('Expected Step, but got text: "%s"%s', $node, $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step, but got text: "%s"%s',
$node,
$this->file ? ' in file: ' . $this->file : ''
));
}

if (!$node instanceof StepNode) {
throw new ParserException(sprintf('Expected Step, but got %s on line: %d%s', $node->getNodeType(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step, but got %s on line: %d%s',
$node->getNodeType(),
$node->getLine(),
$this->file ? ' in file: ' . $this->file : ''
));
}
}

Expand Down Expand Up @@ -358,11 +389,20 @@ protected function parseScenario()
}

if (is_string($node)) {
throw new ParserException(sprintf('Expected Step, but got text: "%s"%s', $node, $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step, but got text: "%s"%s',
$node,
$this->file ? ' in file: ' . $this->file : ''
));
}

if (!$node instanceof StepNode) {
throw new ParserException(sprintf('Expected Step, but got %s on line: %d%s', $node->getNodeType(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step, but got %s on line: %d%s',
$node->getNodeType(),
$node->getLine(),
$this->file ? ' in file: ' . $this->file : ''
));
}
}

Expand Down Expand Up @@ -425,16 +465,30 @@ protected function parseOutline()
}

if (is_string($node)) {
throw new ParserException(sprintf('Expected Step or Examples table, but got text: "%s"%s', $node, $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step or Examples table, but got text: "%s"%s',
$node,
$this->file ? ' in file: ' . $this->file : ''
));
}

if (!$node instanceof StepNode) {
throw new ParserException(sprintf('Expected Step or Examples table, but got %s on line: %d%s', $node->getNodeType(), $node->getLine(), $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Expected Step or Examples table, but got %s on line: %d%s',
$node->getNodeType(),
$node->getLine(),
$this->file ? ' in file: ' . $this->file : ''
));
}
}

if (empty($examples)) {
throw new ParserException(sprintf('Outline should have examples table, but got none for outline "%s" on line: %d%s', rtrim($title), $line, $this->file ? ' in file: ' . $this->file : ''));
throw new ParserException(sprintf(
'Outline should have examples table, but got none for outline "%s" on line: %d%s',
rtrim($title),
$line,
$this->file ? ' in file: ' . $this->file : ''
));
}

return new OutlineNode(rtrim($title) ?: null, $tags, $steps, $examples, $keyword, $line);
Expand Down

0 comments on commit 287c946

Please sign in to comment.