readInt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
require_once __DIR__.'/../vendor/autoload.php';
6
7
use function Scalp\Utils\delay;
8
use function Scalp\Utils\TryCatch;
9
use Scalp\Utils\TryCatch;
10
11
assert_options(ASSERT_ACTIVE, 1);
12
assert_options(ASSERT_EXCEPTION, 1);
0 ignored issues
show
Bug introduced by
The constant ASSERT_EXCEPTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
13
14
function readInt(string $prompt): int
15
{
16
    $input = readline($prompt);
17
18
    assert($input === strval(intval($input)), "String '$input' cannot be converted to Int.");
19
20
    return intval($input);
21
}
22
23
$dividend = TryCatch(delay('readInt', "Enter an Int that you'd like to divide: "));
24
$divisor = TryCatch(delay('readInt', "Enter an Int that you'd like to divide by: "));
25
26
$result = $dividend->flatMap(function (int $x) use ($divisor): TryCatch {
27
    return $divisor->map(function (int $y) use ($x) {
28
        return intdiv($x, $y);
29
    });
30
});
31
32
echo $result."\n";
33