From 5cac0c70a753a2e6e7570677a2d4cd58020246a5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 15 Mar 2020 10:01:00 +0100 Subject: [PATCH] Add missing dots at the end of exception messages --- Lexer.php | 8 ++++---- Node/BinaryNode.php | 4 ++-- Parser.php | 12 ++++++------ ParserCache/ParserCacheAdapter.php | 14 +++++++------- SyntaxError.php | 2 +- TokenStream.php | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Lexer.php b/Lexer.php index 01ca293..e534a56 100644 --- a/Lexer.php +++ b/Lexer.php @@ -59,12 +59,12 @@ public function tokenize($expression) } elseif (false !== strpos(')]}', $expression[$cursor])) { // closing bracket if (empty($brackets)) { - throw new SyntaxError(sprintf('Unexpected "%s"', $expression[$cursor]), $cursor, $expression); + throw new SyntaxError(sprintf('Unexpected "%s".', $expression[$cursor]), $cursor, $expression); } list($expect, $cur) = array_pop($brackets); if ($expression[$cursor] != strtr($expect, '([{', ')]}')) { - throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $cur, $expression); } $tokens[] = new Token(Token::PUNCTUATION_TYPE, $expression[$cursor], $cursor + 1); @@ -87,7 +87,7 @@ public function tokenize($expression) $cursor += \strlen($match[0]); } else { // unlexable - throw new SyntaxError(sprintf('Unexpected character "%s"', $expression[$cursor]), $cursor, $expression); + throw new SyntaxError(sprintf('Unexpected character "%s".', $expression[$cursor]), $cursor, $expression); } } @@ -95,7 +95,7 @@ public function tokenize($expression) if (!empty($brackets)) { list($expect, $cur) = array_pop($brackets); - throw new SyntaxError(sprintf('Unclosed "%s"', $expect), $cur, $expression); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $cur, $expression); } return new TokenStream($tokens, $expression); diff --git a/Node/BinaryNode.php b/Node/BinaryNode.php index bbfe393..549161b 100644 --- a/Node/BinaryNode.php +++ b/Node/BinaryNode.php @@ -148,13 +148,13 @@ public function evaluate($functions, $values) return $left * $right; case '/': if (0 == $right) { - throw new \DivisionByZeroError('Division by zero'); + throw new \DivisionByZeroError('Division by zero.'); } return $left / $right; case '%': if (0 == $right) { - throw new \DivisionByZeroError('Modulo by zero'); + throw new \DivisionByZeroError('Modulo by zero.'); } return $left % $right; diff --git a/Parser.php b/Parser.php index 0930bac..bfc2439 100644 --- a/Parser.php +++ b/Parser.php @@ -99,7 +99,7 @@ public function parse(TokenStream $stream, $names = []) $node = $this->parseExpression(); if (!$stream->isEOF()) { - throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression()); + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression()); } return $node; @@ -195,13 +195,13 @@ public function parsePrimaryExpression() default: if ('(' === $this->stream->current->value) { if (false === isset($this->functions[$token->value])) { - throw new SyntaxError(sprintf('The function "%s" does not exist', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions)); + throw new SyntaxError(sprintf('The function "%s" does not exist.', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, array_keys($this->functions)); } $node = new Node\FunctionNode($token->value, $this->parseArguments()); } else { if (!\in_array($token->value, $this->names, true)) { - throw new SyntaxError(sprintf('Variable "%s" is not valid', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, $this->names); + throw new SyntaxError(sprintf('Variable "%s" is not valid.', $token->value), $token->cursor, $this->stream->getExpression(), $token->value, $this->names); } // is the name used in the compiled code different @@ -227,7 +227,7 @@ public function parsePrimaryExpression() } elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) { $node = $this->parseHashExpression(); } else { - throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $token->type, $token->value), $token->cursor, $this->stream->getExpression()); + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', $token->type, $token->value), $token->cursor, $this->stream->getExpression()); } } @@ -289,7 +289,7 @@ public function parseHashExpression() } else { $current = $this->stream->current; - throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s"', $current->type, $current->value), $current->cursor, $this->stream->getExpression()); + throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', $current->type, $current->value), $current->cursor, $this->stream->getExpression()); } $this->stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); @@ -327,7 +327,7 @@ public function parsePostfixExpression($node) // As a result, if $token is NOT an operator OR $token->value is NOT a valid property or method name, an exception shall be thrown. (Token::OPERATOR_TYPE !== $token->type || !preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A', $token->value)) ) { - throw new SyntaxError('Expected name', $token->cursor, $this->stream->getExpression()); + throw new SyntaxError('Expected name.', $token->cursor, $this->stream->getExpression()); } $arg = new Node\ConstantNode($token->value, true); diff --git a/ParserCache/ParserCacheAdapter.php b/ParserCache/ParserCacheAdapter.php index 38ce659..b9b448d 100644 --- a/ParserCache/ParserCacheAdapter.php +++ b/ParserCache/ParserCacheAdapter.php @@ -67,7 +67,7 @@ public function save(CacheItemInterface $item) */ public function getItems(array $keys = []) { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -75,7 +75,7 @@ public function getItems(array $keys = []) */ public function hasItem($key) { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -83,7 +83,7 @@ public function hasItem($key) */ public function clear() { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -91,7 +91,7 @@ public function clear() */ public function deleteItem($key) { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -99,7 +99,7 @@ public function deleteItem($key) */ public function deleteItems(array $keys) { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -107,7 +107,7 @@ public function deleteItems(array $keys) */ public function saveDeferred(CacheItemInterface $item) { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } /** @@ -115,6 +115,6 @@ public function saveDeferred(CacheItemInterface $item) */ public function commit() { - throw new \BadMethodCallException('Not implemented'); + throw new \BadMethodCallException('Not implemented.'); } } diff --git a/SyntaxError.php b/SyntaxError.php index 12348e6..3340042 100644 --- a/SyntaxError.php +++ b/SyntaxError.php @@ -15,7 +15,7 @@ class SyntaxError extends \LogicException { public function __construct($message, $cursor = 0, $expression = '', $subject = null, array $proposals = null) { - $message = sprintf('%s around position %d', $message, $cursor); + $message = sprintf('%s around position %d', rtrim($message, '.'), $cursor); if ($expression) { $message = sprintf('%s for expression `%s`', $message, $expression); } diff --git a/TokenStream.php b/TokenStream.php index 9096b18..09d3854 100644 --- a/TokenStream.php +++ b/TokenStream.php @@ -53,7 +53,7 @@ public function next() ++$this->position; if (!isset($this->tokens[$this->position])) { - throw new SyntaxError('Unexpected end of expression', $this->current->cursor, $this->expression); + throw new SyntaxError('Unexpected end of expression.', $this->current->cursor, $this->expression); } $this->current = $this->tokens[$this->position]; @@ -70,7 +70,7 @@ public function expect($type, $value = null, $message = null) { $token = $this->current; if (!$token->test($type, $value)) { - throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s)', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor, $this->expression); + throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', $message ? $message.'. ' : '', $token->type, $token->value, $type, $value ? sprintf(' with value "%s"', $value) : ''), $token->cursor, $this->expression); } $this->next(); }