Instantly share code, notes, and snippets.

Embed
What would you like to do?
Snippet from Lyrics.php
<?php
/**
* Class Lyrics
* A class to encapsulate lyrics for a song
*
* @package helloTestable
*/
class Lyrics
{
/**
* @var string
*/
private $fullLyrics;
/**
* Lyrics constructor.
*/
public function __construct($lyricsFile)
{
$this->fullLyrics = file_get_contents($lyricsFile);
}
/**
* Get a single line from the lyrics
*
* @return string
*/
function getLyric()
{
$lyrics = explode("\n", $this->fullLyrics);
// And then randomly choose a line
return wptexturize($lyrics[mt_rand(0, count($lyrics) - 1)]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment