Skip to content

Instantly share code, notes, and snippets.

@eriktorsner
Created April 25, 2017 10:03
Show Gist options
  • Save eriktorsner/9bf6be5c60a14993ac86d8b5fbb20f5a to your computer and use it in GitHub Desktop.
Save eriktorsner/9bf6be5c60a14993ac86d8b5fbb20f5a to your computer and use it in GitHub Desktop.
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