divide()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Scalp\Example {
6
    use function Scalp\None;
7
    use function Scalp\Option;
8
    use Scalp\Option;
9
    use function Scalp\println;
0 ignored issues
show
Bug introduced by
The type Scalp\println was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
    use function Scalp\Some;
11
12
    require_once __DIR__.'/../vendor/autoload.php';
13
14
    function divide(int $x, int $y): Option
15
    {
16
        return $y === 0 ? None() : Some(intdiv($x, $y));
17
    }
18
19
    println(divide(42, 6));
20
    println(divide(42, 0));
21
22
    $option = Option(42);
23
24
    $square = function (int $x): int {
25
        return $x ** 2;
26
    };
27
28
    println($option->map($square));
29
30
    $isOdd = function (int $x): bool {
31
        return $x % 2 === 1;
32
    };
33
34
    println($option->filter($isOdd));
35
36
    $squareRoot = function (int $x): Option {
37
        return $x >= 0 ? Some(sqrt($x)) : None();
38
    };
39
40
    println($option->flatMap($squareRoot));
41
42
    println(None()->map($square));
43
    println(None()->filter($isOdd));
44
    println(None()->flatMap($squareRoot));
45
}
46