Oprydning samt doc blocks

This commit is contained in:
Michal Skogemann 2020-11-07 00:00:00 +01:00
parent 1ef2ed20e3
commit 1e718a0498

View file

@ -28,14 +28,26 @@ class PasswordPhraseGenerator
} }
private function rando($arr) /**
* Random sub element
*
* @param array $arr
* @return array
*/
private function _rando($arr)
{ {
return $arr[array_rand($arr)]; return $arr[array_rand($arr)];
} }
private function word($cla, $conj = null) /**
* Select random word from class
*
* @param string $cla
* @param int $conj
* @return string $word
*/
private function _word($cla, $conj = null)
{ {
global $ord;
$word = $this->ord[$cla][array_rand($this->ord[$cla])]; //rand(0,count($ord[$cla])); $word = $this->ord[$cla][array_rand($this->ord[$cla])]; //rand(0,count($ord[$cla]));
if ($conj == null) { if ($conj == null) {
return $word; return $word;
@ -44,14 +56,20 @@ class PasswordPhraseGenerator
} }
} }
/**
* Main model generator
*
* @param integer $conj
* @return string $phrase
*/
function lego($conj = 0) function lego($conj = 0)
{ {
// 0 = ubestemt ental, eks. "en grim tyr" el. "et dumt æg". // 0 = ubestemt ental, eks. "en grim tyr" el. "et dumt æg".
// 1 = bestemt ental, eks. "den grimme tyr" el. "det dumme æg" // 1 = bestemt ental, eks. "den grimme tyr" el. "det dumme æg"
// 2 = ubestemt flertal, eks. "ægte tedåser" // 2 = ubestemt flertal, eks. "ægte tedåser"
// 3 = bestemt flertal, eks. "de rådne æbler" // 3 = bestemt flertal, eks. "de rådne æbler"
$main = $this->word("sub"); $main = $this->_word("sub");
$desc = $this->word("adj"); $desc = $this->_word("adj");
if ($main[4] == "t") { if ($main[4] == "t") {
$neutrum = true; $neutrum = true;
} else { } else {
@ -61,28 +79,33 @@ class PasswordPhraseGenerator
switch ($conj) { switch ($conj) {
case 0: case 0:
if ($neutrum) { if ($neutrum) {
$phrase = "et " . $this->word("adj")[1] . " " . $main[0]; $phrase = "et " . $this->_word("adj")[1] . " " . $main[0];
} else { } else {
$phrase = "en " . $this->word("adj")[0] . " " . $main[0]; $phrase = "en " . $this->_word("adj")[0] . " " . $main[0];
} }
break; break;
case 1: case 1:
if ($neutrum) { if ($neutrum) {
$phrase = "det " . $this->word("adj")[2] . " " . $main[0]; $phrase = "det " . $this->_word("adj")[2] . " " . $main[0];
} else { } else {
$phrase = "den " . $this->word("adj")[2] . " " . $main[0]; $phrase = "den " . $this->_word("adj")[2] . " " . $main[0];
} }
break; break;
case 2: case 2:
$phrase = $this->word("adj")[2] . " " . $main[2]; $phrase = $this->_word("adj")[2] . " " . $main[2];
break; break;
case 3: case 3:
$phrase = "de " . $this->word("adj")[2] . " " . $main[2]; $phrase = "de " . $this->_word("adj")[2] . " " . $main[2];
break; break;
} }
return $phrase; return $phrase;
} }
/**
* Generate phrase
*
* @return string $phrase
*/
public function generate() public function generate()
{ {
switch ($this->model) { switch ($this->model) {
@ -92,8 +115,8 @@ class PasswordPhraseGenerator
} else { } else {
$b = $this->lego(rand(0, 1)); $b = $this->lego(rand(0, 1));
} }
$c = $this->word("ver", rand(1, 4)); $c = $this->_word("ver", rand(1, 4));
$d = $this->word("sub", $this->rando([1, 3])); $d = $this->_word("sub", $this->_rando([1, 3]));
if (rand(0, 1) > 0) { if (rand(0, 1) > 0) {
$which = rand(1, 3); $which = rand(1, 3);
switch ($which) { switch ($which) {
@ -111,12 +134,12 @@ class PasswordPhraseGenerator
$result = "{$this->tal} $b $c $d{$this->tegn}"; $result = "{$this->tal} $b $c $d{$this->tegn}";
break; break;
case 1: case 1:
$a = $this->lego($this->rando([0, 1, 3])); $a = $this->lego($this->_rando([0, 1, 3]));
$b = $this->word("ver", rand(1, 4)); $b = $this->_word("ver", rand(1, 4));
if ($this->tal > 1) { if ($this->tal > 1) {
$c = $this->word("sub", 2); $c = $this->_word("sub", 2);
} else { } else {
$c = $this->word("sub", $this->rando([1, 3])); $c = $this->_word("sub", $this->_rando([1, 3]));
} }
$result = "$a $b {$this->tal} $c{$this->tegn}"; $result = "$a $b {$this->tal} $c{$this->tegn}";
break; break;