Skip to content

Commit 955b63e

Browse files
committed
corrections after auto-tests
1 parent 039e499 commit 955b63e

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

bin/brain-games

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@
44

55
require_once __DIR__ . '/../vendor/autoload.php';
66
require_once __DIR__ . '/../src/Cli.php';
7-
8-
Src\Cli\runGreeting();

src/Cli.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use function cli\line;
66
use function cli\prompt;
77

8-
function runGreeting()
9-
{
10-
line('Welcome to the Brain Games!');
11-
$name = prompt('May I have your name?');
12-
line("Hello, %s!", $name);
13-
}
8+
line('Welcome to the Brain Games!');
9+
$name = prompt('May I have your name?');
10+
line("Hello, %s!", $name);

src/Engine.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use function cli\line;
44
use function cli\prompt;
55

6-
function runGame($gameName)
6+
function runGame(string $gameName): void
77
{
88
line('Welcome to the Brain Games!');
99
$name = prompt('May I have your name?');
@@ -21,7 +21,7 @@ function runGame($gameName)
2121
$userAnswer = prompt('Your answer');
2222
$correctAnswer = getCorrectAnswer($question);
2323

24-
if ($userAnswer == $correctAnswer) {
24+
if ($userAnswer === (string)$correctAnswer) {
2525
line('Correct!');
2626
$winCount++;
2727
} else {

src/Games/Calc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function generateQuestion(): string
1414
return "$firstOperand $operation $secondOperand";
1515
}
1616

17-
function getCorrectAnswer($question): int
17+
function getCorrectAnswer(string $question): int
1818
{
1919
list($firstOperand, $operation, $secondOperand) = explode(" ", $question);
2020
$firstOperand = (int)$firstOperand;

src/Games/Even.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ function generateQuestion(): int
1010
return random_int(1, 20);
1111
}
1212

13-
function getCorrectAnswer($question): string
13+
function getCorrectAnswer(string $question): string
1414
{
15-
return $question % 2 ? 'no' : 'yes';
15+
//return (int)$question % 2 ? 'no' : 'yes';
16+
if ((int) $question % 2 === 0) {
17+
return "yes";
18+
} else {
19+
return "no";
20+
}
1621
}

src/Games/Gcd.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ function generateQuestion(): string
1818
return "$firstNumber $secondNumber";
1919
}
2020

21-
function getCorrectAnswer($question): int
21+
function getCorrectAnswer(string $question): int
2222
{
2323
list($secondNumber, $firstNumber ) = explode(" ", $question);
2424

2525
$firstNumber = (int)$firstNumber;
2626
$secondNumber = (int)$secondNumber;
2727

28-
if ($secondNumber == 0) {
28+
if ($secondNumber === 0) {
2929
return $firstNumber;
3030
}
3131

32-
while ($secondNumber != 0) {
32+
while ($secondNumber !== 0) {
3333
$temp = $secondNumber;
3434
$secondNumber = $firstNumber % $secondNumber;
3535
$firstNumber = $temp;

src/Games/Prime.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ function generateQuestion(): int
1010
return random_int(1, 101);
1111
}
1212

13-
function getCorrectAnswer($question): string
13+
function getCorrectAnswer(string $question): string
1414
{
1515
$number = (int)$question;
1616
if ($number < 2) {
1717
return 'no';
1818
}
1919

2020
for ($i = 2; $i * $i <= $number; $i++) {
21-
if ($number % $i == 0) {
21+
if ($number % $i === 0) {
2222
return 'no';
2323
}
2424
}

src/Games/Progression.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ function generateQuestion(): string
2727
return generateProgression();
2828
}
2929

30-
function getCorrectAnswer($question): string
30+
function getCorrectAnswer(string $question): string
3131
{
3232
$elements = explode(" ", $question);
33-
$hiddenIndex = array_search("..", $elements);
34-
$intArray = array_map('intval', $elements);
33+
$hiddenIndex = (int)array_search("..", $elements);
34+
$intArray = array_map('intval', $elements, true);
3535
$len = count($elements);
3636

37-
if ($hiddenIndex != 0 && $hiddenIndex != $len - 1) {
37+
if ($hiddenIndex !== 0 && $hiddenIndex !== $len - 1) {
3838
$step = ($intArray[$hiddenIndex + 1] - $intArray[$hiddenIndex - 1]) / 2;
3939
$missedValue = $intArray[$hiddenIndex - 1] + $step;
40-
} elseif ($hiddenIndex == 0) {
41-
$step = $elements[2] - $intArray[1];
40+
} elseif ($hiddenIndex === 0) {
41+
$step = $intArray[2] - $intArray[1];
4242
$missedValue = $intArray[1] - $step;
4343
} else {
4444
$step = $intArray[2] - $intArray[1];

0 commit comments

Comments
 (0)