public function readSynonymsFromFile(string $filepath): array
    {
        if (
            !is_file($filepath) ||
            !is_readable($filepath)
        ) {
            throw SynonymsException::synonymsFileNotFound($filepath);
        }

        $data = file_get_contents($filepath);

        if (!is_string($data)) {
            throw SynonymsException::synonymsMalformedData($filepath);
        }

        return array_filter(array_map(function ($line) {
            if (!is_string($line)) {
                return false;
            }

            $words = str_getcsv($line, ',');

            if (count($words) <= 1) {
                return false;
            }

            return Synonym::createByWords($words);
        }, str_getcsv($data, "\n")));
    }
public function readSynonymsFromFile(string $filepath): array
    {
        if (
            !is_file($filepath) ||
            !is_readable($filepath)
        ) {
            throw SynonymsException::synonymsFileNotFound($filepath);
        }

        $data = file_get_contents($filepath);

        if (!is_string($data)) {
            throw SynonymsException::synonymsMalformedData($filepath);
        }

        return array_filter(array_map(function ($line) {
            if (!is_string($line)) {
                return false;
            }

            $words = str_getcsv($line, ',');

            if (count($words) <= 1) {
                return false;
            }

            return Synonym::createByWords($words);
        }, str_getcsv($data, "\n")));
    }
public function readSynonymsFromFile ( string $ filepath ) : array { if ( ! is_file ( $ filepath ) || ! is_readable ( $ filepath ) ) { throw SynonymsException :: synonymsFileNotFound ( $ filepath ) ; } $ data = file_get_contents ( $ filepath ) ; if ( ! is_string ( $ data ) ) { throw SynonymsException :: synonymsMalformedData ( $ filepath ) ; } return array_filter ( array_map ( function ( $ line ) { if ( ! is_string ( $ line ) ) { return false ; } $ words = str_getcsv ( $ line , ',' ) ; if ( count ( $ words ) <= 1 ) { return false ; } return Synonym :: createByWords ( $ words ) ; } , str_getcsv ( $ data , "\n" ) ) ) ; }
Read synonyms from file.

@param string $filepath

@return Synonym[]

@throws SynonymsException
Read synonyms from file .