Skip to content

Commit

Permalink
Fix 'too many returns' from function
Browse files Browse the repository at this point in the history
  • Loading branch information
thePanz committed Apr 4, 2018
1 parent fb78c47 commit feb20c4
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/Languages/Galach/TokenExtractor/Full.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,63 @@ protected function getExpressionTypeMap()
protected function createTermToken($position, array $data)
{
$lexeme = $data['lexeme'];
$token = null;

switch (true) {
case isset($data['rangeFrom']) && isset($data['rangeTo']):
return new Range(
$token = new Range(
$lexeme,
$position,
$data['domain'],
$data['rangeFrom'], $data['rangeTo']
);
break;

case isset($data['word']):
return new Word(
$token = new Word(
$lexeme,
$position,
$data['domain'],
// un-backslash special characters
preg_replace('/(?:\\\\(\\\\|(["+\-!():#@ ])))/', '$1', $data['word'])
);
break;

case isset($data['phrase']):
$quote = $data['quote'];

return new Phrase(
$token = new Phrase(
$lexeme,
$position,
$data['domain'],
$quote,
// un-backslash quote
preg_replace('/(?:\\\\([' . $quote . ']))/', '$1', $data['phrase'])
);
break;

case isset($data['tag']):
return new Tag(
$token = new Tag(
$lexeme,
$position,
$data['marker'],
$data['tag']
);
break;

case isset($data['user']):
return new User(
$token = new User(
$lexeme,
$position,
$data['marker'],
$data['user']
);
}

throw new RuntimeException('Could not extract term token from the given data');
if (!$token) {
throw new RuntimeException('Could not extract term token from the given data');
}

return $token;
}
}

0 comments on commit feb20c4

Please sign in to comment.