Created
April 25, 2017 10:03
-
-
Save eriktorsner/9bf6be5c60a14993ac86d8b5fbb20f5a to your computer and use it in GitHub Desktop.
Snippet from Lyrics.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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