-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This generator returns 2-word alliterative adjective/animal name pairs. Code updated by @nubs to match standards of the project, but otherwise code was written by @chadicus. Closes #5.
- Loading branch information
Showing
6 changed files
with
849 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
namespace Nubs\RandomNameGenerator; | ||
|
||
use Cinam\Randomizer\Randomizer; | ||
|
||
/** | ||
* Defines an alliterative name generator. | ||
*/ | ||
class Alliteration implements Generator | ||
{ | ||
/** @type array The definition of the potential adjectives. */ | ||
protected $_adjectives; | ||
|
||
/** @type array The definition of the potential nouns. */ | ||
protected $_nouns; | ||
|
||
/** @type Cinam\Randomizer\Randomizer The random number generator. */ | ||
protected $_randomizer; | ||
|
||
/** | ||
* Initializes the Alliteration Generator with the default word lists. | ||
* | ||
* @api | ||
* @param \Cinam\Randomizer\Randomizer $randomizer The random number generator. | ||
*/ | ||
public function __construct(Randomizer $randomizer = null) | ||
{ | ||
$this->_randomizer = $randomizer; | ||
$this->_adjectives = file(__DIR__ . '/adjectives.txt', FILE_IGNORE_NEW_LINES); | ||
$this->_nouns = file(__DIR__ . '/nouns.txt', FILE_IGNORE_NEW_LINES); | ||
} | ||
|
||
/** | ||
* Gets a randomly generated alliterative name. | ||
* | ||
* @api | ||
* @return string A random alliterative name. | ||
*/ | ||
public function getName() | ||
{ | ||
$adjective = $this->_getRandomWord($this->_adjectives); | ||
$noun = $this->_getRandomWord($this->_nouns, $adjective[0]); | ||
|
||
return ucwords("{$adjective} {$noun}"); | ||
} | ||
|
||
/** | ||
* Get a random word from the list of words, optionally filtering by starting letter. | ||
* | ||
* @param array $words An array of words to choose from. | ||
* @param string $startingLetter The desired starting letter of the word. | ||
* @return string The random word. | ||
*/ | ||
protected function _getRandomWord(array $words, $startingLetter = null) | ||
{ | ||
$wordsToSearch = $startingLetter === null ? $words : preg_grep("/^{$startingLetter}/", $words); | ||
return $this->_randomizer ? $this->_randomizer->getArrayValue($wordsToSearch) : $wordsToSearch[array_rand($wordsToSearch)]; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
adorable | ||
adventurous | ||
aggressive | ||
agreeable | ||
alert | ||
alive | ||
amused | ||
angry | ||
annoyed | ||
annoying | ||
anxious | ||
arrogant | ||
ashamed | ||
attractive | ||
average | ||
awful | ||
bad | ||
beautiful | ||
better | ||
bewildered | ||
black | ||
bloody | ||
blue | ||
blue-eyed | ||
blushing | ||
bored | ||
brainy | ||
brave | ||
breakable | ||
bright | ||
busy | ||
calm | ||
careful | ||
cautious | ||
charming | ||
cheerful | ||
clean | ||
clear | ||
clever | ||
cloudy | ||
clumsy | ||
colorful | ||
combative | ||
comfortable | ||
concerned | ||
condemned | ||
confused | ||
cooperative | ||
courageous | ||
crazy | ||
creepy | ||
crowded | ||
cruel | ||
curious | ||
cute | ||
dangerous | ||
dark | ||
dead | ||
defeated | ||
defiant | ||
delightful | ||
depressed | ||
determined | ||
different | ||
difficult | ||
disgusted | ||
distinct | ||
disturbed | ||
dizzy | ||
doubtful | ||
drab | ||
dull | ||
eager | ||
easy | ||
elated | ||
elegant | ||
embarrassed | ||
enchanting | ||
encouraging | ||
energetic | ||
enthusiastic | ||
envious | ||
evil | ||
excited | ||
expensive | ||
exuberant | ||
fair | ||
faithful | ||
famous | ||
fancy | ||
fantastic | ||
fierce | ||
filthy | ||
fine | ||
foolish | ||
fragile | ||
frail | ||
frantic | ||
friendly | ||
frightened | ||
funny | ||
gentle | ||
gifted | ||
glamorous | ||
gleaming | ||
glorious | ||
good | ||
gorgeous | ||
graceful | ||
grieving | ||
grotesque | ||
grumpy | ||
handsome | ||
happy | ||
healthy | ||
helpful | ||
helpless | ||
hilarious | ||
homeless | ||
homely | ||
horrible | ||
hungry | ||
hurt | ||
ill | ||
important | ||
impossible | ||
inexpensive | ||
innocent | ||
inquisitive | ||
itchy | ||
jealous | ||
jittery | ||
jolly | ||
joyous | ||
kind | ||
lazy | ||
light | ||
lively | ||
lonely | ||
long | ||
lovely | ||
lucky | ||
magnificent | ||
misty | ||
modern | ||
motionless | ||
muddy | ||
mushy | ||
mysterious | ||
nasty | ||
naughty | ||
nervous | ||
nice | ||
nutty | ||
obedient | ||
obnoxious | ||
odd | ||
old-fashioned | ||
open | ||
outrageous | ||
outstanding | ||
panicky | ||
perfect | ||
plain | ||
pleasant | ||
poised | ||
poor | ||
powerful | ||
precious | ||
prickly | ||
proud | ||
puzzled | ||
quaint | ||
real | ||
relieved | ||
repulsive | ||
rich | ||
scary | ||
selfish | ||
shiny | ||
shy | ||
silly | ||
sleepy | ||
smiling | ||
smoggy | ||
sore | ||
sparkling | ||
splendid | ||
spotless | ||
stormy | ||
strange | ||
stupid | ||
successful | ||
super | ||
talented | ||
tame | ||
tender | ||
tense | ||
terrible | ||
testy | ||
thankful | ||
thoughtful | ||
thoughtless | ||
tired | ||
tough | ||
troubled | ||
ugliest | ||
ugly | ||
uninterested | ||
unsightly | ||
unusual | ||
upset | ||
uptight | ||
vast | ||
victorious | ||
vivacious | ||
wandering | ||
weary | ||
wicked | ||
wide-eyed | ||
wild | ||
witty | ||
worrisome | ||
worried | ||
wrong | ||
xenophobic | ||
xanthous | ||
xerothermic | ||
yawning | ||
yellowed | ||
yucky | ||
zany | ||
zealous |
Oops, something went wrong.