-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoneFizzBuzz.php
49 lines (42 loc) · 1.04 KB
/
oneFizzBuzz.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/** @var string FIZZ */
const FIZZ = 'Fizz';
/** @var string BUZZ */
const BUZZ = 'Buzz';
/** @var int $theMaxValue */
$theMaxValue = (empty($argv) || !isset($argv[1]) || !is_numeric($argv[1]))
? 20 : intval($argv[1]);
fizzBuzzAndPrintValues(1, $theMaxValue);
/**
* Print the fizzBuzzedValues
*
* @param int $minValue The min value to fizzBuzz
* @param int $maxValue The max value to fizzBuzz
*/
function fizzBuzzAndPrintValues(int $minValue, int $maxValue)
{
for ($i = $minValue; $i <= $maxValue; $i++) {
echo (fizzBuzzAValue($i) . PHP_EOL);
}
}
/**
* Return the processed fizzBuzzAValue for an integer
* @param int $theValue the integer to process
* @return int|string the FizzBuzzedValue
*/
function fizzBuzzAValue(int $theValue)
{
/** @var string $outputVal */
$outputVal = '';
if ($theValue % 3 === 0) {
$outputVal = FIZZ;
}
if ($theValue % 5 === 0) {
$outputVal .= BUZZ;
}
if (empty($outputVal)) {
return $theValue;
} else {
return $outputVal;
}
}