Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-T committed Mar 14, 2024
1 parent 44cb5d4 commit 56c747d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
8 changes: 3 additions & 5 deletions lib/LongitudeOne/Geo/String/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct($input = null)
/**
* @return string[]
*/
protected function getCatchablePatterns()
protected function getCatchablePatterns(): array
{
return [
'[nesw\'",]',
Expand All @@ -62,17 +62,15 @@ protected function getCatchablePatterns()
/**
* @return string[]
*/
protected function getNonCatchablePatterns()
protected function getNonCatchablePatterns(): array
{
return ['\s+'];
}

/**
* @param string &$value
*
* @return int
*/
protected function getType(&$value)
protected function getType(&$value): int
{
if (is_numeric($value)) {
$value += 0;
Expand Down
28 changes: 6 additions & 22 deletions lib/LongitudeOne/Geo/String/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ public function __construct($input = null)
* Parse input string.
*
* @param string|null $input
*
* @return float|int|array
*/
public function parse($input = null)
public function parse($input = null): float|int|array
{
if (null !== $input) {
$this->input = (string) $input;
Expand Down Expand Up @@ -317,11 +315,9 @@ private function number(): int|float
/**
* Match and return single value or pair.
*
* @return float|int|array
*
* @throws UnexpectedValueException
*/
private function point()
private function point(): float|int|array
{
// Get first coordinate value
$x = $this->coordinate();
Expand Down Expand Up @@ -350,14 +346,8 @@ private function point()

/**
* Create out of range exception.
*
* @param string $type
* @param int $high
* @param int $low
*
* @return RangeException
*/
private function rangeError($type, $high, $low = null)
private function rangeError(string $type, int $high, ?int $low = null): RangeException
{
$range = null === $low ? sprintf('greater than %d', $high) : sprintf('out of range %d to %d', $low, $high);
$message = sprintf('[Range Error] Error: %s %s in value "%s"', $type, $range, $this->input);
Expand All @@ -368,11 +358,9 @@ private function rangeError($type, $high, $low = null)
/**
* Match and return seconds value.
*
* @return float|int
*
* @throws RangeException
*/
private function seconds()
private function seconds(): int|float
{
// Seconds value can be an integer or float
if ($this->lexer->isNextTokenAny([Lexer::T_INTEGER, Lexer::T_FLOAT])) {
Expand Down Expand Up @@ -401,10 +389,8 @@ private function seconds()

/**
* Match plus or minus sign and return coefficient.
*
* @return int
*/
private function sign()
private function sign(): int
{
if ($this->lexer->isNextToken(Lexer::T_PLUS)) {
// Match plus and set sign
Expand All @@ -421,10 +407,8 @@ private function sign()

/**
* Match value component symbol if required or present.
*
* @return bool|int|null
*/
private function symbol()
private function symbol(): bool|int|null
{
// If symbol requirement not set match colon if present
if (null === $this->nextSymbol && $this->lexer->isNextToken(Lexer::T_COLON)) {
Expand Down

0 comments on commit 56c747d

Please sign in to comment.