Completed
Push — master ( b93bd2...539d39 )
by Randy
01:46
created

example.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
require_once 'vendor/autoload.php';
4
5
use Optional\Optional;
6
7
function getSome()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
8
{
9
    $a = new FooBar();
10
11
    return Optional::Some($a);
12
}
13
14
function getNone()
0 ignored issues
show
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
15
{
16
    return Optional::None(FooBar::class);
17
}
18
19
print '<pre>';
20
21
$some = getSome();
22
23
var_dump($some->isSome(FooBar::class));
0 ignored issues
show
Security Debugging Code introduced by
var_dump($some->isSome(\FooBar::class)); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
24
var_dump($some->extends(FooBar::class));
25
var_dump($some->is(FooBar::class));
26
var_dump($some->isNone());
27
var_dump($some->getIdentifier());
28
var_dump($some->may(FooBar::class));
29
var_dump($some->unwrap());
30
31
$some->may(FooBar::class)->foo()->bar();
32
33
print PHP_EOL . str_repeat('=', 50) . PHP_EOL;
34
35
$none = getNone();
36
37
var_dump($none->isSome(FooBar::class));
38
var_dump($none->extends(FooBar::class));
39
var_dump($none->is(FooBar::class));
40
var_dump($none->isNone());
41
var_dump($none->getIdentifier());
42
var_dump($none->may(FooBar::class));
43
var_dump($none->unwrap());
44
45
$none->may(FooBar::class)->foo()->bar();
46
47
print PHP_EOL . str_repeat('=', 50) . PHP_EOL;
48
49
$some = Optional::Some(42);
50
51
var_dump($some->isSome('int'));
52
var_dump($some->isSome('float'));
53
var_dump($some->isSome('numeric'));
54
var_dump($some->isSome('scalar'));
55
var_dump($some->isSome('string'));
56
var_dump($some->isSome('bool'));
57
var_dump($some->isSome('array'));
58
var_dump($some->isNone());
59
var_dump($some->is('int'));
60
var_dump($some->is('float'));
61
var_dump($some->is('numeric'));
62
var_dump($some->is('scalar'));
63
var_dump($some->is('string'));
64
var_dump($some->is('bool'));
65
var_dump($some->is('array'));
66
var_dump($some->getIdentifier());
67
var_dump($some->may('int'));
68
var_dump($some->unwrap());
69
70
print PHP_EOL . str_repeat('=', 50) . PHP_EOL;
71
72
$none = Optional::None();
73
74
var_dump($none->isSome('int'));
75
var_dump($none->isSome('float'));
76
var_dump($none->isSome('numeric'));
77
var_dump($none->isSome('scalar'));
78
var_dump($none->isSome('string'));
79
var_dump($none->isSome('bool'));
80
var_dump($none->isSome('array'));
81
var_dump($none->isNone());
82
var_dump($none->is('int'));
83
var_dump($none->is('float'));
84
var_dump($none->is('numeric'));
85
var_dump($none->is('scalar'));
86
var_dump($none->is('string'));
87
var_dump($none->is('bool'));
88
var_dump($none->is('array'));
89
var_dump($none->getIdentifier());
90
var_dump($none->may('int'));
91
var_dump($none->unwrap());
92
93
94