File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ This is VERY VERY **Experimental** .
14
14
* NOT support global variables.
15
15
* NOT support variables in namespace.
16
16
17
+ ##
18
+ ```
19
+ $ composer require --dev struggle-for-php/sfp-psalm-typed-local-variable-plugin
20
+ $ vendor/bin/psalm-plugin enable struggle-for-php/sfp-psalm-typed-local-variable-plugin
21
+ ```
22
+
17
23
## demo
18
24
19
25
``` php
Original file line number Diff line number Diff line change 13
13
use Psalm \Internal \Type \Comparator \UnionTypeComparator ;
14
14
use Psalm \IssueBuffer ;
15
15
use Psalm \StatementsSource ;
16
+ use Psalm \Type \Atomic \TBool ;
17
+ use Psalm \Type \Atomic \TFalse ;
16
18
use Psalm \Type \Atomic \TFloat ;
17
19
use Psalm \Type \Atomic \TInt ;
18
20
use Psalm \Type \Atomic \TLiteralFloat ;
19
21
use Psalm \Type \Atomic \TLiteralInt ;
20
22
use Psalm \Type \Atomic \TLiteralString ;
21
23
use Psalm \Type \Atomic \TString ;
24
+ use Psalm \Type \Atomic \TTrue ;
22
25
use Psalm \Type \Union ;
23
26
use Sfp \Psalm \TypedLocalVariablePlugin \Issue \InvalidScalarTypedLocalVariableIssue ;
24
27
use Sfp \Psalm \TypedLocalVariablePlugin \Issue \InvalidTypedLocalVariableIssue ;
@@ -54,6 +57,8 @@ private static function rollupLiteral(Union $firstDeclare): Union
54
57
$ types [] = new TInt ();
55
58
} elseif ($ atomicType instanceof TLiteralFloat) {
56
59
$ types [] = new TFloat ();
60
+ } elseif ($ atomicType instanceof TFalse || $ atomicType instanceof TTrue) {
61
+ $ types [] = new TBool ();
57
62
} else {
58
63
$ types [] = $ atomicType ;
59
64
}
Original file line number Diff line number Diff line change @@ -65,15 +65,19 @@ function func () : void {
65
65
$float = 0.2;
66
66
// $float = 1; // allowed
67
67
$float = false;
68
+ $bool = false;
69
+ $bool = true;
70
+ $bool = 1;
68
71
}
69
72
CODE
70
73
);
71
74
$ this ->analyzeFile (__METHOD__ , new Context ());
72
75
73
- $ this ->assertSame (3 , IssueBuffer::getErrorCount ());
76
+ $ this ->assertSame (4 , IssueBuffer::getErrorCount ());
74
77
$ this ->assertSame ('$string = false; ' , trim (current (IssueBuffer::getIssuesData ())[0 ]->snippet ));
75
78
$ this ->assertSame ('$int = false; ' , trim (current (IssueBuffer::getIssuesData ())[1 ]->snippet ));
76
79
$ this ->assertSame ('$float = false; ' , trim (current (IssueBuffer::getIssuesData ())[2 ]->snippet ));
80
+ $ this ->assertSame ('$bool = 1; ' , trim (current (IssueBuffer::getIssuesData ())[3 ]->snippet ));
77
81
}
78
82
79
83
/**
You can’t perform that action at this time.
0 commit comments