Skip to content

Commit 607ac80

Browse files
authored
Merge pull request #6 from sasezaki/hotfix/boolean
support bool
2 parents cfa8085 + af67889 commit 607ac80

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This is VERY VERY **Experimental** .
1414
* NOT support global variables.
1515
* NOT support variables in namespace.
1616

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+
1723
## demo
1824

1925
```php

src/AssignAnalyzer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
1414
use Psalm\IssueBuffer;
1515
use Psalm\StatementsSource;
16+
use Psalm\Type\Atomic\TBool;
17+
use Psalm\Type\Atomic\TFalse;
1618
use Psalm\Type\Atomic\TFloat;
1719
use Psalm\Type\Atomic\TInt;
1820
use Psalm\Type\Atomic\TLiteralFloat;
1921
use Psalm\Type\Atomic\TLiteralInt;
2022
use Psalm\Type\Atomic\TLiteralString;
2123
use Psalm\Type\Atomic\TString;
24+
use Psalm\Type\Atomic\TTrue;
2225
use Psalm\Type\Union;
2326
use Sfp\Psalm\TypedLocalVariablePlugin\Issue\InvalidScalarTypedLocalVariableIssue;
2427
use Sfp\Psalm\TypedLocalVariablePlugin\Issue\InvalidTypedLocalVariableIssue;
@@ -54,6 +57,8 @@ private static function rollupLiteral(Union $firstDeclare): Union
5457
$types[] = new TInt();
5558
} elseif ($atomicType instanceof TLiteralFloat) {
5659
$types[] = new TFloat();
60+
} elseif ($atomicType instanceof TFalse || $atomicType instanceof TTrue) {
61+
$types[] = new TBool();
5762
} else {
5863
$types[] = $atomicType;
5964
}

tests/Unit/TypedLocalVariableCheckerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,19 @@ function func () : void {
6565
$float = 0.2;
6666
// $float = 1; // allowed
6767
$float = false;
68+
$bool = false;
69+
$bool = true;
70+
$bool = 1;
6871
}
6972
CODE
7073
);
7174
$this->analyzeFile(__METHOD__, new Context());
7275

73-
$this->assertSame(3, IssueBuffer::getErrorCount());
76+
$this->assertSame(4, IssueBuffer::getErrorCount());
7477
$this->assertSame('$string = false;', trim(current(IssueBuffer::getIssuesData())[0]->snippet));
7578
$this->assertSame('$int = false;', trim(current(IssueBuffer::getIssuesData())[1]->snippet));
7679
$this->assertSame('$float = false;', trim(current(IssueBuffer::getIssuesData())[2]->snippet));
80+
$this->assertSame('$bool = 1;', trim(current(IssueBuffer::getIssuesData())[3]->snippet));
7781
}
7882

7983
/**

0 commit comments

Comments
 (0)