anonymous()
last analyzed

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 2
dl 0
loc 1
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\Conversion\AnyToString;
8
use function Scalp\PatternMatching\match;
9
use function Scalp\PatternMatching\Any;
0 ignored issues
show
Bug introduced by
The type Scalp\PatternMatching\Any 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\PatternMatching\Value;
0 ignored issues
show
Bug introduced by
The type Scalp\PatternMatching\Value 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...
11
use function Scalp\PatternMatching\Type;
0 ignored issues
show
Bug introduced by
The type Scalp\PatternMatching\Type 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...
12
use function Scalp\concat;
0 ignored issues
show
Bug introduced by
The type Scalp\concat 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...
13
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...
14
use function Scalp\Some;
15
use function Scalp\Pair;
0 ignored issues
show
Bug introduced by
The type Scalp\Pair 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...
16
use Scalp\None;
17
use Scalp\Some;
18
use Scalp\Tuple;
19
20
function returnString(string $s): callable
21
{
22
    return function () use ($s): string {
23
        return $s;
24
    };
25
}
26
27
$res0 = match(42)
28
    ->case(Any(), function (): string { return 'Anything'; })
29
    ->done();
30
31
println($res0);
32
33
$res1 = match(Some(42))
34
    ->case(Any(), function (): string { return 'Anything'; })
35
    ->done();
36
37
println($res1);
38
39
$res2 = match(42)
40
    ->case(Value(13), function (): string { return 'Number 13'; })
41
    ->case(Value('42'), function (): string { return 'String "42"'; })
42
    ->case(Value(42), function (): string { return 'Number 42'; })
43
    ->case(Any(), function (): string { return 'Fallback'; })
44
    ->done();
45
46
println($res2);
47
48
$res3 = match(Some(42))
49
    ->case(Value(Some(13)), function (): string { return 'Some 13'; })
50
    ->case(Value(Some(42)), function (): string { return 'Some 42'; })
51
    ->case(Any(), function (): string { return 'Fallback'; })
52
    ->done();
53
54
println($res3);
55
56
$res4 = match(Some(42))
57
    ->case(Value(Some(13)), function (): string { return 'Some 13'; })
58
    ->case(Value(Some('42')), function (): string { return 'Some 42'; })
59
    ->case(Any(), function (): string { return 'Fallback'; })
60
    ->done();
61
62
println($res4);
63
64
$res5 = match(42)
65
    ->case(Type('string'), function (): string { return 'String'; })
0 ignored issues
show
Bug introduced by
Type('string') of type string is incompatible with the type Scalp\PatternMatching\Pattern\Pattern expected by parameter $pattern of Scalp\PatternMatching\Un...vedMatchSubject::case(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
    ->case(/** @scrutinizer ignore-type */ Type('string'), function (): string { return 'String'; })
Loading history...
66
    ->case(Type('integer'), function (): string { return 'Integer'; })
0 ignored issues
show
Bug introduced by
Type('integer') of type string is incompatible with the type Scalp\PatternMatching\Pattern\Pattern expected by parameter $pattern of Scalp\PatternMatching\MatchSubject::case(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
    ->case(/** @scrutinizer ignore-type */ Type('integer'), function (): string { return 'Integer'; })
Loading history...
67
    ->case(Any(), function (): string { return 'Not integer'; })
68
    ->done();
69
70
println($res5);
71
72
$res6 = match(Some(42))
73
    ->case(Type(None::class), function (): string { return 'None'; })
74
    ->case(Type(Some::class), function (): string { return 'Some'; })
75
    ->case(Any(), function (): string { return 'Neither'; })
76
    ->done();
77
78
println($res6);
79
80
$res7 = match(Some(42))
81
    ->case(Type(Some::class, Value('42')), returnString('Inner value is string'))
0 ignored issues
show
Unused Code introduced by
The call to type() has too many arguments starting with Value('42'). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
    ->case(/** @scrutinizer ignore-call */ Type(Some::class, Value('42')), returnString('Inner value is string'))

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
82
    ->case(Type(Some::class, Value(42)), returnString('Inner value is integer'))
83
    ->case(Any(), returnString('Fallback'))
84
    ->done();
85
86
println($res7);
87
88
$res8 = match(Pair('2 * 7 = ', 14))
89
    ->case(
90
        Type(Tuple::class, Any()->bind(), Any()->bind()),
91
        function (string $question, int $answer): string { return concat('Solution: ', $question, AnyToString($answer)); }
92
    )
93
    ->case(Any(), returnString('Fallback'))
94
    ->done();
95
96
println($res8);
97