dara-tobi / urbandict

Dictionary of common modern slangs
MIT License
1 stars 1 forks source link

FindSlang.php #3

Open unicodeveloper opened 9 years ago

unicodeveloper commented 9 years ago
 public function find(DictStore $dictStore, $slang)
    {
        $dictionary = $dictStore->dictData;
        $checkSlangExists = $this->getIndex($dictionary, $slang);
        if ($checkSlangExists === false) {
            return false;
        } else {
            $slangIndex = $checkSlangExists;
            $slang = [];
            $slang['index'] = $slangIndex;
            $slang['meaning'] = $dictionary[$slangIndex]['description'];
            $slang['example'] = $dictionary[$slangIndex]['sample-sentence'];
            return $slang;
        }
    }
 $slang = [];
 $slang['index'] = $slangIndex;
 $slang['meaning'] = $dictionary[$slangIndex]['description'];
 $slang['example'] = $dictionary[$slangIndex]['sample-sentence'];
  return $slang;

should be abstracted into another function and then called here.

 if ($checkSlangExists === false) {
            return false;
        } 

is like saying check if false === false return false :flushed:

You should throw an exception instead, something like

if( ! $checkSlangExists ) {
  throw NotFoundException("blah..blah..blah");
} else {
  $this->theNewSlangFunctionYouCreated();
}